From 6a65245cccaf22b5883141f14e580f33b6a3ab8a Mon Sep 17 00:00:00 2001 From: Andrey Sorokin Date: Thu, 13 Feb 2020 14:37:51 +0300 Subject: [PATCH] fix ios closed initialState issue --- src/CollapsibleNavBarScrollView.tsx | 9 +++------ src/constants.ts | 5 +++++ src/index.ts | 9 ++------- tsconfig.json | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) create mode 100644 src/constants.ts diff --git a/src/CollapsibleNavBarScrollView.tsx b/src/CollapsibleNavBarScrollView.tsx index dedc764..6240d93 100644 --- a/src/CollapsibleNavBarScrollView.tsx +++ b/src/CollapsibleNavBarScrollView.tsx @@ -13,8 +13,6 @@ import { Animated, ScrollView, View, - Dimensions, - Platform, NativeSyntheticEvent, NativeScrollEvent, ScrollViewProps, @@ -29,8 +27,7 @@ import { CollapsibleNavBarState, CollapsibleNavBarActionOptions, } from './types' - -const { height: SCREEN_HEIGHT } = Dimensions.get('window') +import { SCREEN_HEIGHT, isAndroid } from './constants' export const CollapsibleNavBarScrollView = memo( forwardRef( @@ -137,7 +134,7 @@ export const CollapsibleNavBarScrollView = memo( (e: NativeSyntheticEvent) => { isDraging.current = false const velocity = e.nativeEvent.velocity?.y || 0 - if (velocity === 0 || (Platform.OS === 'android' && Math.abs(Math.round(velocity)) <= 2)) { + if (velocity === 0 || (isAndroid && Math.abs(Math.round(velocity)) <= 2)) { handleIntermediateState() } }, @@ -155,7 +152,7 @@ export const CollapsibleNavBarScrollView = memo( const handleLayout = useCallback( (event: LayoutChangeEvent) => { - if (firstRender.current && initialState === CollapsibleNavBarState.closed) { + if (firstRender.current && initialState === CollapsibleNavBarState.closed && isAndroid) { close({ animated: false }) } if (onLayout) { diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..b490f56 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,5 @@ +import { Dimensions, Platform } from 'react-native' + +export const SCREEN_HEIGHT = Dimensions.get('window').height + +export const isAndroid = Platform.OS === 'android' diff --git a/src/index.ts b/src/index.ts index fe9501b..04e4d27 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,2 @@ -export { CollapsibleNavBarScrollView } from './CollapsibleNavBarScrollView' -export { - CollapsibleNavBarActionOptions, - CollapsibleNavBarState, - CollapsibleNavBarScrollViewProps, - CollapsibleNavBarScrollViewRef, -} from './types' +export * from './CollapsibleNavBarScrollView' +export * from './types' diff --git a/tsconfig.json b/tsconfig.json index 61eeccf..2239694 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "outDir": "dist", "module": "esnext", - "target": "es5", + "target": "ESNext", "lib": ["es6", "dom", "es2016", "es2017"], "sourceMap": true, "allowJs": false,