Theta Client Guide Update - React Native - Theta Client SDK 1.2

Hello Yall!

Added in a new small guide about running the theta client 1.2 SDK using the React Native demo provided by RICOH.

I’ve added comments enabled on my Guide in the website so if guys want you can make comments for any problems, ideas, cool facts etc.

Here is a sneak peak :eyes:

To get access to this sign up here
SDK Guide

2 Likes

Testing out the new Features with getOptions() in the React Native Theta-client library but so far the values only show up in the console. In the future I’ll update this to show it working in a react native app.
‘Capture Mode: IMAGE’ shows its working.

image

Here is my Repo that I’m using to work on the React Native Demo.

I’ve finished adding the Get Options button in the React Native Demo. Here is the code for it.

It shows the 6 new properties available that are listed here.

1 Like

Can you please provide the step to set up the react native project on the macOS m1 chip. I have read the document but didn’t find any doc for the mac

Thanks

In the directory ./demos/demo-react-native do

yarn install
yarn run android

You must have the Android SDK and yarn installed as well as set the environmental variable for THETA_CLIENT

for iOS, it is

yarn run ios

Please post the problem you are encountering.

1 Like

For initial setup and installation, it’s posted here in the Official Documentation. theta-client/react-native at main · ricohapi/theta-client · GitHub. I believe they use Linux to set up the demo, which should have similar commands to the MacOS terminal.

Initial Setup: theta-client/react-native at main · ricohapi/theta-client · GitHub
Running Demo: theta-client/demos/demo-react-native at main · ricohapi/theta-client · GitHub

I can talk to @jcasman and @craig about adding a Mac Version to the guide.

2 Likes

Update Post

I added Fake Theta Functionality to the Demo App.

Here is the code:

To test it out, uncomment the fake URL

And comment out the real URL.

Results are shown here:





1 Like

I’m not sure, but I think the engineers at RICOH use a Mac, likely because it can run both the iOS and Android emulators.

Thanks for the support I will review the link you have provide and let you know if found any issue

@erikrod1 and @craig I have follow the step provide from your end in this thread. In the android its working fine.

For the iOS when I have tried with fake url its provide me this error “TLS sessions are not supported on Native platform.” its working fine on the android and provide the list as well.

I am using this url to connect the camera “https://fake-theta.vercel.app”. Can you please help me out here.

Thanks
Dilip

It does not seem possible to use fake-theta with iOS right now

@craig Thanks to point out this here. I will check with real device and let you know if face any issue

Thanks for the quick response

1 Like

It may be possible to use fake-theta with iOS in the future. However, right now, there is a problem with the https.

1 Like

@erikrod1 and @craig I have done the demo on the android. and its working fine with fetch the exiting photo from the actual device. I have provide the option to take the photo and see the live preview as well.

  1. Showing the live preview on the react native is not working fine and flicker issue. I have read the comment on this link of github.
    So to fix this issue I have put the delay on the update the preview and now its working much better still facing the issue of the blinking but for now we can view the preview for the same. Let me know if you have suggestion to avoid the blinking issue.
    Here is the code for the same.
var updateUrl = true;

useEffect(() => {
    const interval = setInterval(() => {
      updateUrl = true;
    }, 1000);

    return () => clearInterval(interval);
  }, []);

const eventListener = emitter.addListener(THETA_EVENT_NAME, event => {
        if (updateUrl == true) {
          updateUrl = false;
          setDataUrl(event.data);
        }
      });
  1. Other issue which I am facing here is when I am taking the photo first time and called the method of stopLivePreview it crash on the android and provide the error like this “Could not invoke ThetaClientReactNative.stopLivePreview” I have attached the image for the same in the below.

Here is the full code of the take photo screen.

import React, {useEffect} from 'react';
import {
  Alert,
  Image,
  NativeEventEmitter,
  NativeModules,
  PermissionsAndroid,
  Platform,
  SafeAreaView,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
} from 'react-native';
import RNFS from 'react-native-fs';
import {
  getLivePreview,
  stopLivePreview,
  getPhotoCaptureBuilder,
  THETA_EVENT_NAME,
} from 'theta-client-react-native';
import {useIsFocused} from '@react-navigation/native';

const Preview = props => {
  const {navigation} = props;
  const [dataUrl, setDataUrl] = React.useState();
  var updateUrl = true;
  const isFocused = useIsFocused();

  const startLivePreview = async () => {
    try {
      getLivePreview().then(x => {});
    } catch (error) {
      console.log('preview error', error);
    }
  };

  useEffect(() => {
    const interval = setInterval(() => {
      updateUrl = true;
    }, 1000);
    return () => clearInterval(interval);
  }, []);

  useEffect(() => {
    if (isFocused) {
      const emitter = new NativeEventEmitter(
        NativeModules.ThetaClientReactNative,
      );
      const eventListener = emitter.addListener(THETA_EVENT_NAME, event => {
        if (updateUrl == true) {
          updateUrl = false;
          setDataUrl(event.data);
        }
      });
      startLivePreview();
      return () => {
        stopLivePreview();
        eventListener.remove();
      };
    }
  }, [isFocused]);

  const getPath =
    Platform.OS == 'android'
      ? RNFS.DownloadDirectoryPath
      : RNFS.DocumentDirectoryPath;

  const checkStoragePermission = async () => {
    if (Platform.OS === 'ios') {
      return true;
    } else {
      try {
        var permission = false;
        if (Platform.constants.Release >= 13) {
          const grants = await PermissionsAndroid.requestMultiple([
            PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES,
            PermissionsAndroid.PERMISSIONS.READ_MEDIA_VIDEO,
          ]);
          if (
            grants['android.permission.READ_MEDIA_IMAGES'] ===
              PermissionsAndroid.RESULTS.GRANTED &&
            grants['android.permission.READ_MEDIA_VIDEO'] ===
              PermissionsAndroid.RESULTS.GRANTED
          ) {
            permission = true;
          } else {
            permission = false;
          }
        } else {
          const grants = await PermissionsAndroid.requestMultiple([
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
            PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
          ]);
          if (
            grants['android.permission.WRITE_EXTERNAL_STORAGE'] ===
              PermissionsAndroid.RESULTS.GRANTED &&
            grants['android.permission.READ_EXTERNAL_STORAGE'] ===
              PermissionsAndroid.RESULTS.GRANTED
          ) {
            permission = true;
          } else {
            permission = false;
          }
        }
        return permission;
      } catch (err) {
        return false;
      }
    }
  };

  const takePhoto = async () => {
    let permission = await checkStoragePermission();
    if (permission) {
      try {
        const photoCapture = await getPhotoCaptureBuilder().build();
        const url = await photoCapture.takePicture();
        let filename = url.substring(url.lastIndexOf('/') + 1, url.length);
        var path = `file://${getPath}/${filename}`;
        RNFS.downloadFile({
          fromUrl: url,
          toFile: path,
        }).promise.then(async r => {
          Alert.alert(
            'Capture Image',
            `Here is the url for the same \n\n${path}`,
          );
          setDataUrl(path);
          navigation.goBack();
        });
      } catch (error) {
        Alert.alert(`${error}`);
      }
    } else {
      Alert.alert('', `Please provide storage permission to save the image.`);
    }
  };

  return (
    <View style={{flex: 1, backgroundColor: 'white'}}>
      <SafeAreaView style={{flex: 1}}>
        <View style={{flex: 1}}>
          {dataUrl != undefined && dataUrl != '' && (
            <Image
              style={styles.takePhoto}
              source={{uri: dataUrl}}
              fadeDuration={0}
            />
          )}
        </View>
        <TouchableOpacity
          onPress={takePhoto}
          style={{
            marginHorizontal: 20,
            alignItems: 'center',
            padding: 20,
            backgroundColor: 'black',
            borderRadius: 10,
            marginVertical: 20,
          }}>
          <Text style={{color: 'white', fontSize: 20}}>Take Photo</Text>
        </TouchableOpacity>
      </SafeAreaView>
    </View>
  );
};

const styles = StyleSheet.create({
  takePhoto: {
    width: '100%',
    height: '100%',
    backgroundColor: 'white',
    resizeMode: 'contain',
    zIndex: 0,
    elevation: 0,
  },
});

export default Preview;

Can you you please review once this and let me know if you have suggestion for the same.

Thanks
Dilip

1 Like

Looks good, I can test it out when I get back in the office and post results here.

2 Likes

@erikrod1 Did you get chance to look into the issue which I am facing on the android to capture the photo. I have already share the code sample and image on the above thread.

Thanks

@erikrod1 if you have time, you should try the React Native demo with the new 1.5 version of theta-client using a physical device camera and physical device Android phone or tablet. I haven’t tried the React Native demo, only the Android and Flutter demos.

@dilip please add your experience to this issue on GitHub.

Sure I will try and let you know

1 Like

live preview on Android from React Native works with theta-client 1.6

Tested with React Native Demo Android on Google Pixel 4a physical device and THETA X with fw 2.30