Skip to content
This repository was archived by the owner on Nov 26, 2019. It is now read-only.

Commit 7bc1922

Browse files
committed
Try to setup react-native-screens
This seems super-buggy atm. On Android, initially this seems to work, but as soon as you start swiping and then release, no gestures such as touch work after that. Same issue can also be reproduced if you just leave all screens active. Seems to be software-mansion/react-native-screens#61 On iOS, I get `undefined is not an object (evaluating 'this._ref.setNativeProps')`. The `ref` is undefined for some reason only on iOS: https://github.com/kmagiera/react-native-screens/blob/acf80e640c584bf4019cfaf9356ee44b09e7dc99/src/screens.native.js#L44 If you do `active={focused ? 1 : 0}`, it works as expected on Android (though not desirable). However, on iOS, no gestures such as touch seem to work.
1 parent b57666d commit 7bc1922

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
2-
import { View, Text, Button, StyleSheet } from 'react-native';
2+
import { View, Text, Button, Platform, StyleSheet } from 'react-native';
3+
import { useScreens } from 'react-native-screens';
34
import Stack, { SceneProps, Route } from './components/Stack';
45

56
type CustomRoute = Route & { initial?: boolean };
@@ -73,6 +74,8 @@ export default class App extends React.Component<{}, State> {
7374
}
7475
}
7576

77+
useScreens(true);
78+
7679
const styles = StyleSheet.create({
7780
item: {
7881
margin: 8,

src/components/Stack.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
2-
import { View, StyleSheet, LayoutChangeEvent } from 'react-native';
2+
import { StyleSheet, LayoutChangeEvent, ViewProps } from 'react-native';
3+
import { Screen, ScreenContainer } from 'react-native-screens';
34
import Animated from 'react-native-reanimated';
45
import Card from './Card';
56
import { SlideFromRightIOS } from '../TransitionConfigs/TransitionPresets';
@@ -33,6 +34,15 @@ type State<T> = {
3334
layout: Layout;
3435
};
3536

37+
const { cond, eq } = Animated;
38+
39+
// @ts-ignore
40+
const AnimatedScreen = Animated.createAnimatedComponent(
41+
Screen
42+
) as React.ComponentType<
43+
ViewProps & { active: number | Animated.Node<number> }
44+
>;
45+
3646
export default class Stack<T extends Route> extends React.Component<
3747
Props<T>,
3848
State<T>
@@ -89,7 +99,7 @@ export default class Stack<T extends Route> extends React.Component<
8999
}))}
90100
onGoBack={onGoBack}
91101
/>
92-
<View
102+
<ScreenContainer
93103
style={styles.container}
94104
onLayout={this.handleLayout}
95105
pointerEvents={layout.height && layout.width ? 'box-none' : 'none'}
@@ -102,8 +112,14 @@ export default class Stack<T extends Route> extends React.Component<
102112
: undefined;
103113

104114
return (
105-
<View
115+
<AnimatedScreen
106116
key={route.key}
117+
active={
118+
// Mark focused screen to be always active
119+
// Mark unfocused screen as active if the next screen is currently transitioning
120+
// Coz the screen will be visible underneath next screen when it's transitioning
121+
focused ? 1 : next ? cond(eq(next, 1), 0, 1) : 1
122+
}
107123
accessibilityElementsHidden={!focused}
108124
importantForAccessibility={
109125
focused ? 'auto' : 'no-hide-descendants'
@@ -126,10 +142,10 @@ export default class Stack<T extends Route> extends React.Component<
126142
index,
127143
})}
128144
</Card>
129-
</View>
145+
</AnimatedScreen>
130146
);
131147
})}
132-
</View>
148+
</ScreenContainer>
133149
</React.Fragment>
134150
);
135151
}

0 commit comments

Comments
 (0)