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

Commit 279ef91

Browse files
committed
Basic implementation of screen header
1 parent f026959 commit 279ef91

22 files changed

Lines changed: 529 additions & 62 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
.DS_Store
2+
13
node_modules
24
.expo

src/App.tsx

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,75 @@
11
import * as React from 'react';
22
import { View, Text, Button, StyleSheet } from 'react-native';
33
import Stack, { SceneProps, Route } from './components/Stack';
4-
import Card from './components/Card';
5-
import { SlideFromRightIOS } from './TransitionConfigs/TransitionPresets';
64

75
type CustomRoute = Route & { initial?: boolean };
86

97
type State = {
108
routes: CustomRoute[];
11-
closing: string[];
9+
initialRoutes: string[];
10+
closingRoutes: string[];
1211
};
1312

1413
export default class App extends React.Component<{}, State> {
1514
state: State = {
16-
routes: [{ key: '0', initial: true }, { key: '1', initial: true }],
17-
closing: [],
15+
routes: [{ key: '0' }, { key: '1' }],
16+
initialRoutes: ['0', '1'],
17+
closingRoutes: [],
1818
};
1919

2020
private key = 2;
2121

22-
private renderScene = (
23-
{ route, ...rest }: SceneProps<CustomRoute>,
24-
index: number
25-
) => {
22+
private renderScene = ({ route, index }: SceneProps<CustomRoute>) => {
2623
return (
27-
<Card
28-
{...rest}
29-
closing={this.state.closing.includes(route.key)}
30-
onClose={() =>
31-
this.setState(state => ({
32-
routes: state.routes.filter(r => r !== route),
33-
closing: state.closing.filter(key => key !== route.key),
34-
}))
35-
}
36-
gesturesEnabled={index !== 0}
37-
animationsEnabled={!route.initial}
38-
{...SlideFromRightIOS}
39-
>
40-
<View style={styles.scene}>
41-
<Text style={styles.item}>{index}</Text>
24+
<View style={styles.scene}>
25+
<Text style={styles.item}>{index}</Text>
26+
<View style={styles.item}>
27+
<Button
28+
title="Add screen"
29+
onPress={() => {
30+
this.setState(state => ({
31+
routes: [...state.routes, { key: String(this.key++) }],
32+
}));
33+
}}
34+
/>
35+
</View>
36+
{index !== 0 ? (
4237
<View style={styles.item}>
4338
<Button
44-
title="Add screen"
45-
onPress={() => {
39+
title="Go back"
40+
onPress={() =>
4641
this.setState(state => ({
47-
routes: [...state.routes, { key: String(this.key++) }],
48-
}));
49-
}}
42+
closingRoutes: [...state.closingRoutes, route.key],
43+
}))
44+
}
5045
/>
5146
</View>
52-
{index !== 0 ? (
53-
<View style={styles.item}>
54-
<Button
55-
title="Go back"
56-
onPress={() =>
57-
this.setState(state => ({
58-
closing: [...state.closing, route.key],
59-
}))
60-
}
61-
/>
62-
</View>
63-
) : null}
64-
</View>
65-
</Card>
47+
) : null}
48+
</View>
6649
);
6750
};
6851

6952
render() {
70-
return <Stack routes={this.state.routes} renderScene={this.renderScene} />;
53+
return (
54+
<Stack
55+
routes={this.state.routes}
56+
initialRoutes={this.state.initialRoutes}
57+
closingRoutes={this.state.closingRoutes}
58+
onGoBack={({ route }) =>
59+
this.setState(state => ({
60+
closingRoutes: [...state.closingRoutes, route.key],
61+
}))
62+
}
63+
onCloseRoute={({ route }) =>
64+
this.setState(state => ({
65+
routes: state.routes.filter(r => r !== route),
66+
closingRoutes: state.closingRoutes.filter(key => key !== route.key),
67+
initialRoutes: state.initialRoutes.filter(key => key !== route.key),
68+
}))
69+
}
70+
renderScene={this.renderScene}
71+
/>
72+
);
7173
}
7274
}
7375

src/assets/back-icon-mask.png

1.58 KB
Loading

src/assets/back-icon.png

290 Bytes
Loading
134 Bytes
Loading

src/assets/back-icon@1.5x.ios.png

373 Bytes
Loading
100 Bytes
Loading

src/assets/back-icon@1x.ios.png

290 Bytes
Loading
134 Bytes
Loading

src/assets/back-icon@2x.ios.png

405 Bytes
Loading

0 commit comments

Comments
 (0)