|
|
@@ -38,6 +38,7 @@ import {
|
|
|
import Modal from "../modal";
|
|
|
|
|
|
const BottomSheet: RefForwardingComponent<IBottomSheetRef, IBottomSheetProps> = ({
|
|
|
+ isContentReady: isContentReadyProp = true,
|
|
|
renderHeader: RenderHeaderComponent,
|
|
|
renderBottom: RenderBottomComponent,
|
|
|
isForceFullScreenOnSwipe = false,
|
|
|
@@ -143,6 +144,8 @@ const BottomSheet: RefForwardingComponent<IBottomSheetRef, IBottomSheetProps> =
|
|
|
const isSwipeCloseRef = useRef(isSwipeClose);
|
|
|
const isCanSwipeRef = useRef(isCanSwipe);
|
|
|
|
|
|
+ const isContentReadyRef = useRef(isContentReadyProp);
|
|
|
+
|
|
|
if(!isWorkAsFullScreen && !isCanFullScreenOnSwipe && snapPoint) {
|
|
|
maxHeight.current = snapPoint;
|
|
|
}
|
|
|
@@ -155,6 +158,9 @@ const BottomSheet: RefForwardingComponent<IBottomSheetRef, IBottomSheetProps> =
|
|
|
},
|
|
|
open: () => {
|
|
|
setIsActive(true);
|
|
|
+ },
|
|
|
+ setIsContentReady: (status) => {
|
|
|
+ isContentReadyRef.current = status;
|
|
|
}
|
|
|
}),
|
|
|
[]
|
|
|
@@ -176,6 +182,10 @@ const BottomSheet: RefForwardingComponent<IBottomSheetRef, IBottomSheetProps> =
|
|
|
isWorkAsFullScreenRef.current = isWorkAsFullScreen;
|
|
|
}, [isWorkAsFullScreen]);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ isContentReadyRef.current = isContentReadyProp;
|
|
|
+ }, [isContentReadyProp]);
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (!isMeasured || contentHeight.current === -1) return;
|
|
|
|
|
|
@@ -186,7 +196,7 @@ const BottomSheet: RefForwardingComponent<IBottomSheetRef, IBottomSheetProps> =
|
|
|
}
|
|
|
|
|
|
if (isActive) {
|
|
|
- openAnimation();
|
|
|
+ open();
|
|
|
}
|
|
|
}, [
|
|
|
isActive,
|
|
|
@@ -196,7 +206,9 @@ const BottomSheet: RefForwardingComponent<IBottomSheetRef, IBottomSheetProps> =
|
|
|
if(isActiveProp !== undefined) {
|
|
|
useEffect(() => {
|
|
|
setIsActive(isActiveProp);
|
|
|
- }, [isActiveProp]);
|
|
|
+ }, [
|
|
|
+ isActiveProp
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -279,7 +291,29 @@ const BottomSheet: RefForwardingComponent<IBottomSheetRef, IBottomSheetProps> =
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const openAnimation = () => {
|
|
|
+ const openAnimation = (runIndex?: number) => {
|
|
|
+ if(isContentReadyRef.current) {
|
|
|
+ Animated.timing(animatedTranslateY, {
|
|
|
+ useNativeDriver: false,
|
|
|
+ duration: 300,
|
|
|
+ toValue: 0
|
|
|
+ }).start(({
|
|
|
+ finished
|
|
|
+ }) => {
|
|
|
+ if(finished) {
|
|
|
+ if(onOpened) onOpened();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ if(!runIndex || runIndex < 10) {
|
|
|
+ setTimeout(() => {
|
|
|
+ openAnimation(runIndex ? runIndex + 1 : 1);
|
|
|
+ }, 100);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const open = () => {
|
|
|
if (translateYValue.current < 0) {
|
|
|
const safeValue = snapPoint ?? contentHeight.current;
|
|
|
animatedTranslateY.setValue(safeValue);
|
|
|
@@ -294,17 +328,9 @@ const BottomSheet: RefForwardingComponent<IBottomSheetRef, IBottomSheetProps> =
|
|
|
|
|
|
if(onOpen) onOpen();
|
|
|
|
|
|
- Animated.timing(animatedTranslateY, {
|
|
|
- useNativeDriver: false,
|
|
|
- duration: 300,
|
|
|
- toValue: 0
|
|
|
- }).start(({
|
|
|
- finished
|
|
|
- }) => {
|
|
|
- if(finished) {
|
|
|
- if(onOpened) onOpened();
|
|
|
- }
|
|
|
- });
|
|
|
+ setTimeout(() => {
|
|
|
+ openAnimation();
|
|
|
+ }, 100);
|
|
|
};
|
|
|
|
|
|
const closeAnimation = (toValue?: number, _onClosed?: (props: {
|