1
- import { Camera , Filament , Model , useCameraManipulator } from 'react-native-filament '
2
- import React , { useCallback , useState } from 'react'
1
+ import React from 'react'
2
+ import { Camera , FilamentContext , FilamentView , Model , useCameraManipulator } from 'react-native-filament '
3
3
import { Gesture , GestureDetector } from 'react-native-gesture-handler'
4
- import { LayoutChangeEvent , StyleSheet , View } from 'react-native'
4
+ import { Dimensions , StyleSheet , View } from 'react-native'
5
5
import { useSharedValue } from 'react-native-worklets-core'
6
6
import { DefaultLight } from './components/DefaultLight'
7
7
@@ -15,17 +15,13 @@ function Scene() {
15
15
} )
16
16
17
17
// Pan gesture
18
- const [ viewHeight , setViewHeight ] = useState < number > ( ) // As we need to invert the Y axis we must know the view height
18
+ const viewHeight = Dimensions . get ( 'window' ) . height
19
19
const panGesture = Gesture . Pan ( )
20
20
. onBegin ( ( event ) => {
21
- if ( viewHeight == null ) return
22
-
23
21
const yCorrected = viewHeight - event . translationY
24
22
cameraManipulator ?. grabBegin ( event . translationX , yCorrected , false ) // false means rotation instead of translation
25
23
} )
26
24
. onUpdate ( ( event ) => {
27
- if ( viewHeight == null ) return
28
-
29
25
const yCorrected = viewHeight - event . translationY
30
26
cameraManipulator ?. grabUpdate ( event . translationX , yCorrected )
31
27
} )
@@ -49,27 +45,25 @@ function Scene() {
49
45
} )
50
46
const combinedGesture = Gesture . Race ( pinchGesture , panGesture )
51
47
52
- const onLayout = useCallback ( ( event : LayoutChangeEvent ) => {
53
- setViewHeight ( event . nativeEvent . layout . height )
54
- } , [ ] )
55
-
56
48
return (
57
49
< GestureDetector gesture = { combinedGesture } >
58
- < View onLayout = { onLayout } style = { styles . container } >
50
+ < FilamentView style = { styles . container } >
59
51
< Camera cameraManipulator = { cameraManipulator } />
60
52
< DefaultLight />
61
53
62
54
< Model source = { { uri : modelPath } } transformToUnitCube />
63
- </ View >
55
+ </ FilamentView >
64
56
</ GestureDetector >
65
57
)
66
58
}
67
59
68
60
export function CameraPan ( ) {
69
61
return (
70
- < Filament >
71
- < Scene />
72
- </ Filament >
62
+ < View style = { styles . container } >
63
+ < FilamentContext >
64
+ < Scene />
65
+ </ FilamentContext >
66
+ </ View >
73
67
)
74
68
}
75
69
0 commit comments