@momo-kits/foundation 0.80.8-beta.11 → 0.80.8-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Application/ModalScreen.tsx +23 -7
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import React, {useContext, useEffect, useMemo, useRef} from 'react';
|
|
1
|
+
import React, {useContext, useEffect, useMemo, useRef, useState} from 'react';
|
|
2
2
|
import {
|
|
3
|
+
Dimensions,
|
|
4
|
+
Keyboard,
|
|
3
5
|
KeyboardAvoidingView,
|
|
4
6
|
Platform,
|
|
5
7
|
Pressable,
|
|
6
8
|
StyleSheet,
|
|
7
9
|
View,
|
|
8
|
-
Keyboard,
|
|
9
10
|
} from 'react-native';
|
|
10
11
|
import {SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
11
12
|
import {
|
|
@@ -90,6 +91,7 @@ const Modal: React.FC<ModalParams> = props => {
|
|
|
90
91
|
const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
91
92
|
const insets = useSafeAreaInsets();
|
|
92
93
|
const {theme, navigator} = useContext(ApplicationContext);
|
|
94
|
+
const [keyboardSnap, setKeyboardSnap] = useState(0);
|
|
93
95
|
const {screen, options, snapPoint}: BottomSheetParams = props.route.params;
|
|
94
96
|
const Component = useRef(screen).current;
|
|
95
97
|
const navigation = new Navigation(props.navigation, theme);
|
|
@@ -102,28 +104,41 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
102
104
|
|
|
103
105
|
const snapPoints = useMemo(() => {
|
|
104
106
|
if (snapPoint) {
|
|
105
|
-
|
|
107
|
+
const current = parseInt(snapPoint) + keyboardSnap * 100;
|
|
108
|
+
return [`${current}%`];
|
|
106
109
|
}
|
|
107
110
|
return ['50%', '70%', '90%'];
|
|
108
|
-
}, []);
|
|
111
|
+
}, [keyboardSnap]);
|
|
109
112
|
|
|
110
113
|
const bottomSheetRef = useRef<any>(null);
|
|
111
114
|
const mountedRef = useRef(true);
|
|
112
115
|
|
|
113
116
|
let backgroundColor = theme.colors.background.default;
|
|
117
|
+
let bottomInset = keyboardSnap * Dimensions.get('window').height;
|
|
118
|
+
if (bottomInset > 16) {
|
|
119
|
+
bottomInset -= 16;
|
|
120
|
+
}
|
|
114
121
|
if (options?.surface) {
|
|
115
122
|
backgroundColor = theme.colors.background.surface;
|
|
116
123
|
}
|
|
117
124
|
|
|
118
125
|
useEffect(() => {
|
|
119
|
-
const keyboardDidShow = Keyboard.addListener('keyboardDidShow',
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
const keyboardDidShow = Keyboard.addListener('keyboardDidShow', e => {
|
|
127
|
+
setKeyboardSnap(
|
|
128
|
+
e.endCoordinates.height / Dimensions.get('window').height,
|
|
129
|
+
);
|
|
130
|
+
bottomSheetRef.current?.expand();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const keyboardDidHide = Keyboard.addListener('keyboardDidHide', () => {
|
|
134
|
+
setKeyboardSnap(0);
|
|
135
|
+
});
|
|
122
136
|
|
|
123
137
|
bottomSheetRef.current?.present();
|
|
124
138
|
return () => {
|
|
125
139
|
mountedRef.current = false;
|
|
126
140
|
keyboardDidShow.remove();
|
|
141
|
+
keyboardDidHide.remove();
|
|
127
142
|
};
|
|
128
143
|
}, []);
|
|
129
144
|
|
|
@@ -145,6 +160,7 @@ const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
|
145
160
|
navigator?.pop();
|
|
146
161
|
}
|
|
147
162
|
}}
|
|
163
|
+
bottomInset={bottomInset}
|
|
148
164
|
handleComponent={null}
|
|
149
165
|
backdropComponent={backdropComponent}>
|
|
150
166
|
<BottomSheetView accessibilityLabel={'BottomSheet'}>
|