Skip to content

Commit

Permalink
fix ios closed initialState issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sorokin0andrey committed Feb 13, 2020
1 parent 47c5323 commit 6a65245
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
9 changes: 3 additions & 6 deletions src/CollapsibleNavBarScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
Animated,
ScrollView,
View,
Dimensions,
Platform,
NativeSyntheticEvent,
NativeScrollEvent,
ScrollViewProps,
Expand All @@ -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<CollapsibleNavBarScrollViewRef | null, CollapsibleNavBarScrollViewProps & ScrollViewProps>(
Expand Down Expand Up @@ -137,7 +134,7 @@ export const CollapsibleNavBarScrollView = memo(
(e: NativeSyntheticEvent<NativeScrollEvent>) => {
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()
}
},
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Dimensions, Platform } from 'react-native'

export const SCREEN_HEIGHT = Dimensions.get('window').height

export const isAndroid = Platform.OS === 'android'
9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
export { CollapsibleNavBarScrollView } from './CollapsibleNavBarScrollView'
export {
CollapsibleNavBarActionOptions,
CollapsibleNavBarState,
CollapsibleNavBarScrollViewProps,
CollapsibleNavBarScrollViewRef,
} from './types'
export * from './CollapsibleNavBarScrollView'
export * from './types'
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"outDir": "dist",
"module": "esnext",
"target": "es5",
"target": "ESNext",
"lib": ["es6", "dom", "es2016", "es2017"],
"sourceMap": true,
"allowJs": false,
Expand Down

0 comments on commit 6a65245

Please sign in to comment.