Advertisement
Guest User

Untitled

a guest
Nov 4th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. constructor(props) {
  2.    super(props);
  3.  
  4.    this.state = {
  5.     initialized: false,
  6.     arVisible: true,
  7.   };
  8.  
  9.   this._onInitialized = this._onInitialized.bind(this);
  10. }
  11.  
  12. onBack = () => {
  13.   this.setState({
  14.     arVisible: false,
  15.   }, () => {
  16.     this.props.navigation.goBack();
  17.   });
  18. }
  19.  
  20. _onInitialized(state, reason) {
  21.   if (state === ViroConstants.TRACKING_NORMAL || state === ViroConstants.TRACKING_LIMITED) {
  22.     if (!this.state.initialized) {
  23.       this.setState({
  24.         initialized: true,
  25.       });
  26.     }
  27.   }
  28. }
  29.  
  30. _renderARScene = () => {
  31.   const {initialized, position} = this.state;
  32.  
  33.   return (
  34.     <ViroARScene onTrackingUpdated={this._onInitialized}>
  35.       {initialized && position !== undefined && (
  36.         <ViroButton
  37.           source={{
  38.             uri: this.state.nearTreasure.getARThumb(),
  39.           }}
  40.           position={position}
  41.           height={2}
  42.           width={2}
  43.           scale={[1, 1, 1]}
  44.           transformBehaviors={['billboard']}
  45.           onClickState={(state) => {
  46.             if (state === 3) {
  47.               this.onClickTreasure();
  48.             }
  49.           }}
  50.           onClick={this.onClickTreasure}
  51.         />
  52.       )}
  53.     </ViroARScene>
  54.   );
  55. }
  56.  
  57. render() {
  58.   const {nearTreasure, arVisible} = this.state;
  59.  
  60.   return (
  61.     <View style={styles.container}>
  62.       <SafeAreaView style={{backgroundColor: 'white'}}>
  63.         <View style={styles.statusBar}>
  64.           <StatusBar backgroundColor="white" translucent barStyle="dark-content" />
  65.         </View>
  66.         <View style={{height: NAVIGATION_BAR_HEIGHT, alignItems: 'center', flexDirection: 'row', paddingHorizontal: 11}}>
  67.           {...}
  68.         </View>
  69.       </SafeAreaView>
  70.       {arVisible && (
  71.         <ViroARSceneNavigator
  72.           style={{flex: 1}}
  73.           worldAlignment="GravityAndHeading"
  74.           initialScene={{
  75.             scene: this._renderARScene,
  76.           }}
  77.         />
  78.       )}
  79.       <SafeAreaView style={{position: 'absolute', bottom: 0, left: 0, right: 0, paddingVertical: 14}}>
  80.         <View style={{paddingHorizontal: 14, marginHorizontal: 14, paddingBottom: 32, paddingTop: 18, alignItems: 'center'}}>
  81.           {...}
  82.         </View>
  83.       </SafeAreaView>
  84.     </View>
  85.   );
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement