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

Commit 49db3c8

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 4343af6 commit 49db3c8

2 files changed

Lines changed: 31 additions & 10 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
import Card from './components/Card';
56
import { SlideFromRightIOS } from './TransitionConfigs/TransitionPresets';
@@ -71,6 +72,8 @@ export default class App extends React.Component<{}, State> {
7172
}
7273
}
7374

75+
useScreens(true);
76+
7477
const styles = StyleSheet.create({
7578
item: {
7679
margin: 8,

src/components/Stack.tsx

Lines changed: 27 additions & 9 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

56
export type Route = { key: string };
@@ -28,6 +29,15 @@ type State<T> = {
2829
layout: Layout;
2930
};
3031

32+
const { cond, eq } = Animated;
33+
34+
// @ts-ignore
35+
const AnimatedScreen = Animated.createAnimatedComponent(
36+
Screen
37+
) as React.ComponentType<
38+
ViewProps & { active: number | Animated.Node<number> }
39+
>;
40+
3141
export default class Stack<T extends Route> extends React.Component<
3242
Props<T>,
3343
State<T>
@@ -67,17 +77,27 @@ export default class Stack<T extends Route> extends React.Component<
6777
const { layout, progress } = this.state;
6878

6979
return (
70-
<View
80+
<ScreenContainer
7181
style={styles.container}
7282
onLayout={this.handleLayout}
7383
pointerEvents={layout.height && layout.width ? 'auto' : 'none'}
7484
>
7585
{routes.map((route, index, self) => {
7686
const focused = index === self.length - 1;
87+
const current = progress[route.key];
88+
const next = self[index + 1]
89+
? progress[self[index + 1].key]
90+
: undefined;
7791

7892
return (
79-
<View
93+
<AnimatedScreen
8094
key={route.key}
95+
active={
96+
// Mark focused screen to be always active
97+
// Mark unfocused screen as active if the next screen is currently transitioning
98+
// Coz the screen will be visible underneath next screen when it's transitioning
99+
focused ? 1 : next ? cond(eq(next, 1), 0, 1) : 1
100+
}
81101
accessibilityElementsHidden={!focused}
82102
importantForAccessibility={
83103
focused ? 'auto' : 'no-hide-descendants'
@@ -88,17 +108,15 @@ export default class Stack<T extends Route> extends React.Component<
88108
{
89109
route,
90110
layout,
91-
current: progress[route.key],
92-
next: self[index + 1]
93-
? progress[self[index + 1].key]
94-
: undefined,
111+
current,
112+
next,
95113
},
96114
index
97115
)}
98-
</View>
116+
</AnimatedScreen>
99117
);
100118
})}
101-
</View>
119+
</ScreenContainer>
102120
);
103121
}
104122
}

0 commit comments

Comments
 (0)