Skip to content

Commit

Permalink
fix: initial mounting flicker (#115)
Browse files Browse the repository at this point in the history
* chore: updated hooks dependencies for some variables

* chore: updated initial opacity control to be in native thread

* chore: rename internal components

* chore: updated examples
  • Loading branch information
gorhom authored Dec 15, 2020
1 parent fe2d385 commit 113da47
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ const AppearanceProvider = ({ children }: AppearanceProviderProps) => {
return () => {
Appearance.removeChangeListener(handleAppearanceChange);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [handleAppearanceChange]);
return (
<AppearanceContext.Provider value={contextValue}>
{children}
Expand Down
3 changes: 1 addition & 2 deletions example/src/components/weather/Weather.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const Weather = ({ animatedPosition, snapPoints }: WeatherProps) => {
},
],
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[snapPoints, appearance]
[appearance, animatedPosition, snapPoints]
);
return (
<Animated.View style={containerStyle}>
Expand Down
1 change: 0 additions & 1 deletion example/src/screens/advanced/MapExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ const MapExample = () => {
topInset={topSafeArea}
animatedPosition={animatedModalPosition}
handleComponent={LocationDetailsHandle}
backdropComponent={renderBackdrop}
backgroundComponent={BlurredBackground}
>
<LocationDetails
Expand Down
17 changes: 13 additions & 4 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
useScrollable,
useNormalizedSnapPoints,
usePropsValidator,
useReactiveValue,
} from '../../hooks';
import {
BottomSheetInternalProvider,
Expand Down Expand Up @@ -154,6 +155,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
// eslint-disable-next-line react-hooks/exhaustive-deps
[containerHeight, handleHeight]
);
const animatedIsLayoutReady = useReactiveValue(isLayoutCalculated ? 1 : 0);

//#endregion

//#region variables
Expand Down Expand Up @@ -233,10 +236,10 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
handlePanGestureTranslationY,
handlePanGestureVelocityY,
scrollableContentOffsetY,
animatedIsLayoutReady,
snapPoints,
initialPosition,
currentIndexRef,
isLayoutCalculated,
onAnimate: handleOnAnimate,
});

Expand Down Expand Up @@ -406,12 +409,18 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
const containerStyle = useMemo<Animated.AnimateStyle<ViewStyle>>(
() => ({
...styles.container,
opacity: isLayoutCalculated ? 1 : 0,
opacity: animatedIsLayoutReady,
transform: [
{ translateY: isLayoutCalculated ? position : safeContainerHeight },
{
translateY: cond(
animatedIsLayoutReady,
position,
safeContainerHeight
),
},
],
}),
[safeContainerHeight, position, isLayoutCalculated]
[safeContainerHeight, position, animatedIsLayoutReady]
);
const contentContainerStyle = useMemo(
() => ({
Expand Down
2 changes: 1 addition & 1 deletion src/components/bottomSheet/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface BottomSheetAnimationConfigs {
export interface BottomSheetTransitionConfig
extends Required<BottomSheetAnimationConfigs>,
Pick<BottomSheetProps, 'onAnimate'> {
isLayoutCalculated: boolean;
animatedIsLayoutReady: Animated.Value<number>;

contentPanGestureState: Animated.Value<State>;
contentPanGestureTranslationY: Animated.Value<number>;
Expand Down
7 changes: 3 additions & 4 deletions src/components/bottomSheet/useTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { useReactiveValue, useReactiveValues } from '../../hooks';
import type { BottomSheetTransitionConfig } from './types';

export const useTransition = ({
isLayoutCalculated,
animatedIsLayoutReady,
animationDuration,
animationEasing,
contentPanGestureState,
Expand All @@ -42,7 +42,6 @@ export const useTransition = ({
initialPosition,
onAnimate,
}: BottomSheetTransitionConfig) => {
const isReady = useReactiveValue(isLayoutCalculated ? 1 : 0);
const currentGesture = useValue<GESTURE>(GESTURE.UNDETERMINED);
const currentPosition = useReactiveValue(initialPosition);
const snapPoints = useReactiveValues(_snapPoints);
Expand Down Expand Up @@ -154,7 +153,7 @@ export const useTransition = ({
() =>
block([
cond(
eq(isReady, 1),
animatedIsLayoutReady,
[
// debug('current gesture', currentGesture),
/**
Expand Down Expand Up @@ -309,7 +308,7 @@ export const useTransition = ({
),
]),
[
isReady,
animatedIsLayoutReady,
animationState,
clock,
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,15 @@ const BottomSheetDraggableViewComponent = ({
},
},
]),
// eslint-disable-next-line react-hooks/exhaustive-deps
[gestureType]
[
gestureType,
contentPanGestureState,
contentPanGestureTranslationY,
contentPanGestureVelocityY,
handlePanGestureState,
handlePanGestureTranslationY,
handlePanGestureVelocityY,
]
);

// effects
Expand Down
2 changes: 1 addition & 1 deletion src/components/bottomSheetDraggableView/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './DraggableView';
export { default } from './BottomSheetDraggableView';
3 changes: 1 addition & 2 deletions src/components/view/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const BottomSheetViewComponent = ({
// callback
const handleSettingScrollable = useCallback(() => {
scrollableContentOffsetY.setValue(0);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [scrollableContentOffsetY]);

// effects
useFocusHook(handleSettingScrollable);
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/useBottomSheet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { useContext } from 'react';
import { BottomSheetContext } from '../contexts/external';

export const useBottomSheet = () => {
return useContext(BottomSheetContext);
};
export const useBottomSheet = () => useContext(BottomSheetContext);
5 changes: 2 additions & 3 deletions src/hooks/useBottomSheetInternal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useContext } from 'react';
import { BottomSheetInternalContext } from '../contexts/internal';

export const useBottomSheetInternal = () => {
return useContext(BottomSheetInternalContext);
};
export const useBottomSheetInternal = () =>
useContext(BottomSheetInternalContext);
6 changes: 2 additions & 4 deletions src/hooks/useScrollableInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export const useScrollableInternal = (type: ScrollableType) => {
},
},
]),
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
[scrollableContentOffsetY]
);
const handleSettingScrollable = useCallback(() => {
_scrollableContentOffsetY.setValue(scrollableContentOffsetYRef.current);
Expand All @@ -50,8 +49,7 @@ export const useScrollableInternal = (type: ScrollableType) => {
return () => {
removeScrollableRef(scrollableRef);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [type, _scrollableContentOffsetY, removeScrollableRef, setScrollableRef]);

// effects
useCode(
Expand Down

0 comments on commit 113da47

Please sign in to comment.