azesmway / react-native-unity

MIT License
272 stars 66 forks source link

going back from unity view screen and screen becomes black #101

Open primekhan555 opened 8 months ago

primekhan555 commented 8 months ago

https://drive.google.com/file/d/1tJ5ceBkfDaSFztuVe7GPGlrwlvpvk5oZ/view?usp=sharing

check this video the face button in bottom navigation will open UnityView

below is the code any help is appreciated Thank you

import { ImageBackground, StatusBar, Image, TouchableOpacity, View, } from 'react-native'; import React, {useRef, useEffect} from 'react'; import Images from '../../../Styles/Images'; import styles from './Styles'; import UnityView from '@azesmway/react-native-unity'; import {useNavigation} from '@react-navigation/native';

export default function FaceInteraction(): React.JSX.Element { const navigation = useNavigation(); const unityRef = useRef(null);

useEffect(() => { // SendData(jsonedData); }, []); const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); async function SendData(data: any) { await delay(500); console.log('data is sended from react native'); unityRef.current?.postMessage('ReactToUnity', 'GetDatas', data); // },5000); } const unityData = { name: "I'm Stepa", age: 253, }; let jsonedData = JSON.stringify(unityData);

useEffect(() => { // navigation.navigate('Unity') return () => { unityRef.current?.componentWillUnmount(); }; }, []);

return ( <View style={{flex: 1}}> <UnityView ref={unityRef} style={{height: '100%', width: '100%'}} androidKeepPlayerMounted={true} // fullScreen={true} // onPlayerQuit={f => {console.log("onPlayerQuit")}} // onPlayerUnload={f => {console.log("onPlayerQuit")}} onUnityMessage={result => { console.log('data is received from unity'); console.log('Message Here : ', result.nativeEvent.message); let d = result.nativeEvent.message; if (d.includes('home')) { console.log('name existttttttt'); navigation.navigate('BottomNavigation', {screen: 'HomeTab'}); } }} />

); }

primekhan555 commented 8 months ago

@azesmway please help

DigohD commented 8 months ago

Are you using a tab navigator from react-navigation/native?

In that case we have the same issue with this specific setup. Will let you know if and when we figure out how to solve it or a workaround. Please let us know if you find a way as well.

primekhan555 commented 8 months ago

@DigohD androidKeepPlayerMounted={true} if you make it false then this work goodalso i have raised another issue of keyboard which is also solved with androidKeepPlayerMounted={false} , but then when you navigate to another screen again navigate to unity screen then unity does not render,

DigohD commented 7 months ago

Thanks, the screen indeed goes black with androidKeepPlayerMounted={false}. In our case we now only hit a black screen whenever we open up a link to another application and then return to the app.

kenhung-hk commented 6 hours ago

https://github.com/kenhung-hk/react-native-unity I've made some fixes on the iOS side, and it should be working now. I'll submit a PR once I've addressed the Android issues.