1
- import React , { Component } from 'react' ;
2
- import { StyleSheet } from 'react-native' ;
1
+ import React , { useState } from 'react' ;
2
+ import { StyleSheet } from 'react-native' ;
3
3
import {
4
4
ViroARScene ,
5
5
ViroText ,
6
6
ViroConstants ,
7
- ViroARSceneNavigator
7
+ ViroARSceneNavigator ,
8
8
} from '@viro-community/react-viro' ;
9
9
10
- class HelloWorldSceneAR extends Component {
10
+ const HelloWorldSceneAR = ( ) => {
11
+ const [ text , setText ] = useState ( 'Initializing AR...' ) ;
11
12
12
- constructor ( props ) {
13
- super ( props ) ;
14
- // Set initial state here
15
- this . state = {
16
- text : "Initializing AR..."
17
- } ;
18
- // bind 'this' to functions
19
- this . _onInitialized = this . _onInitialized . bind ( this ) ;
20
- }
21
-
22
- render ( ) {
23
- return (
24
- < ViroARScene onTrackingUpdated = { this . _onInitialized } >
25
- < ViroText text = { this . state . text } scale = { [ .5 , .5 , .5 ] } position = { [ 0 , 0 , - 1 ] } style = { styles . helloWorldTextStyle } />
26
- </ ViroARScene >
27
- ) ;
28
- }
29
-
30
- _onInitialized ( state , reason ) {
31
- if ( state == ViroConstants . TRACKING_NORMAL ) {
32
- this . setState ( {
33
- text : "Hello World!"
34
- } ) ;
35
- } else if ( state == ViroConstants . TRACKING_NONE ) {
13
+ function onInitialized ( state , reason ) {
14
+ console . log ( 'guncelleme' , state , reason ) ;
15
+ if ( state === ViroConstants . TRACKING_NORMAL ) {
16
+ setText ( 'Hello World!' ) ;
17
+ } else if ( state === ViroConstants . TRACKING_NONE ) {
36
18
// Handle loss of tracking
37
19
}
38
20
}
39
- }
21
+
22
+ return (
23
+ < ViroARScene onTrackingUpdated = { onInitialized } >
24
+ < ViroText
25
+ text = { text }
26
+ scale = { [ 0.5 , 0.5 , 0.5 ] }
27
+ position = { [ 0 , 0 , - 1 ] }
28
+ style = { styles . helloWorldTextStyle }
29
+ />
30
+ </ ViroARScene >
31
+ ) ;
32
+ } ;
33
+
34
+ export default ( ) => {
35
+ return (
36
+ < ViroARSceneNavigator
37
+ autofocus = { true }
38
+ initialScene = { {
39
+ scene : HelloWorldSceneAR ,
40
+ } }
41
+ style = { styles . f1 }
42
+ />
43
+ ) ;
44
+ } ;
40
45
41
46
var styles = StyleSheet . create ( {
47
+ f1 : { flex : 1 } ,
42
48
helloWorldTextStyle : {
43
49
fontFamily : 'Arial' ,
44
50
fontSize : 30 ,
@@ -47,17 +53,3 @@ var styles = StyleSheet.create({
47
53
textAlign : 'center' ,
48
54
} ,
49
55
} ) ;
50
-
51
- export default class App extends React . Component {
52
- render ( ) {
53
- return (
54
- < ViroARSceneNavigator
55
- autofocus = { true }
56
- initialScene = { {
57
- scene : HelloWorldSceneAR ,
58
- } }
59
- style = { { flex : 1 } }
60
- />
61
- ) ;
62
- }
63
- }
0 commit comments