1
1
import { useRef } from 'react'
2
- import { Text , View , type TextStyle , type ViewStyle } from 'react-native'
3
- import { TrueSheet } from '@lodev09/react-native-true-sheet'
2
+ import { Text , TouchableOpacity , View , type StyleProp , type TextStyle , type ViewStyle } from 'react-native'
3
+ import { TrueSheet , type SizeInfo } from '@lodev09/react-native-true-sheet'
4
4
import MapView from 'react-native-maps'
5
+ import { useSafeAreaInsets } from 'react-native-safe-area-context'
6
+ import Animated , { useSharedValue , withSpring , useAnimatedStyle , useEvent , useHandler } from 'react-native-reanimated'
5
7
6
8
import {
7
9
BasicSheet ,
@@ -12,7 +14,10 @@ import {
12
14
ScrollViewSheet ,
13
15
} from '../components/sheets'
14
16
import { Button , Spacer } from '../components'
15
- import { BLUE , DARK , GRAY , SPACING } from '../utils'
17
+ import { BLUE , DARK , GRAY , SPACING , SPRING_CONFIG } from '../utils'
18
+
19
+ const AnimatedButton = Animated . createAnimatedComponent ( TouchableOpacity )
20
+ const AnimatedTrueSheet = Animated . createAnimatedComponent ( TrueSheet )
16
21
17
22
export const MapScreen = ( ) => {
18
23
const sheetRef = useRef < TrueSheet > ( null )
@@ -24,11 +29,54 @@ export const MapScreen = () => {
24
29
const gestureSheet = useRef < TrueSheet > ( null )
25
30
const blankSheet = useRef < TrueSheet > ( null )
26
31
32
+ const insets = useSafeAreaInsets ( )
33
+ const buttonY = useSharedValue ( 0 )
34
+
35
+ const handlers = {
36
+ onDragChange : ( e : SizeInfo , _ : Record < string , unknown > ) => {
37
+ 'worklet'
38
+ buttonY . value = - e . value
39
+ } ,
40
+ }
41
+
42
+ const { context, doDependenciesDiffer } = useHandler ( handlers , [ ] )
43
+
44
+ const dragChangeHandler = useEvent < SizeInfo > (
45
+ ( event ) => {
46
+ 'worklet'
47
+ console . log ( event )
48
+ const { onDragChange } = handlers
49
+ if ( onDragChange && event . eventName . endsWith ( 'onDragChange' ) ) {
50
+ onDragChange ( event , context )
51
+ }
52
+ } ,
53
+ [ 'onDragChange' ] ,
54
+ doDependenciesDiffer ,
55
+ )
56
+
27
57
const presentBasicSheet = async ( index = 0 ) => {
28
58
await basicSheet . current ?. present ( index )
29
59
console . log ( 'Sheet 1 present async' )
30
60
}
31
61
62
+ const $mapStyleButtonStyles : StyleProp < ViewStyle > = [
63
+ $mapStyle ,
64
+ { bottom : insets . bottom + SPACING } ,
65
+ useAnimatedStyle ( ( ) => ( {
66
+ transform : [
67
+ { translateY : buttonY . value }
68
+ ]
69
+ } ) )
70
+ ]
71
+
72
+ const handlePresent = ( sizeInfo : SizeInfo ) => {
73
+ buttonY . value = withSpring ( - sizeInfo . value , SPRING_CONFIG )
74
+ }
75
+
76
+ const handleOnDragEnd = ( sizeInfo : SizeInfo ) => {
77
+ buttonY . value = withSpring ( - sizeInfo . value , SPRING_CONFIG )
78
+ }
79
+
32
80
return (
33
81
< View style = { $container } >
34
82
< MapView
@@ -46,7 +94,8 @@ export const MapScreen = () => {
46
94
userInterfaceStyle = "dark"
47
95
/>
48
96
49
- < TrueSheet
97
+ < AnimatedButton activeOpacity = { 0.6 } style = { $mapStyleButtonStyles } />
98
+ < AnimatedTrueSheet
50
99
sizes = { [ '15%' , 'auto' , 'large' ] }
51
100
ref = { sheetRef }
52
101
blurTint = "dark"
@@ -57,6 +106,9 @@ export const MapScreen = () => {
57
106
dismissible = { false }
58
107
cornerRadius = { 12 }
59
108
initialIndex = { 1 }
109
+ onPresent = { handlePresent }
110
+ onDragChange = { dragChangeHandler }
111
+ onDragEnd = { handleOnDragEnd }
60
112
// initialIndexAnimated={false}
61
113
onMount = { ( ) => {
62
114
// sheetRef.current?.present(1)
@@ -84,11 +136,25 @@ export const MapScreen = () => {
84
136
< FlatListSheet ref = { flatListSheet } />
85
137
< GestureSheet ref = { gestureSheet } />
86
138
< BlankSheet ref = { blankSheet } />
87
- </ TrueSheet >
139
+ </ AnimatedTrueSheet >
88
140
</ View >
89
141
)
90
142
}
91
143
144
+ const $mapStyle : ViewStyle = {
145
+ position : 'absolute' ,
146
+ right : SPACING ,
147
+ height : SPACING * 3 ,
148
+ width : SPACING * 3 ,
149
+ borderRadius : ( SPACING * 3 ) / 2 ,
150
+ backgroundColor : BLUE ,
151
+ shadowColor : DARK ,
152
+ shadowOffset : { width : 0 , height : 2 } ,
153
+ shadowOpacity : 0.3 ,
154
+ shadowRadius : 2 ,
155
+ elevation : 4 ,
156
+ }
157
+
92
158
const $container : ViewStyle = {
93
159
backgroundColor : BLUE ,
94
160
justifyContent : 'center' ,
0 commit comments