|
| 1 | +import React from 'react'; |
| 2 | +import { Text, View, StyleSheet } from 'react-native'; |
| 3 | +import { NavigationProps } from 'react-native-navigation'; |
| 4 | +import Root from '../components/Root'; |
| 5 | +import Button from '../components/Button'; |
| 6 | +import Navigation from '../services/Navigation'; |
| 7 | +import Screens from './Screens'; |
| 8 | +import testIDs from '../testIDs'; |
| 9 | + |
| 10 | +let sharedData: string | null = null; |
| 11 | + |
| 12 | +interface Props extends NavigationProps { |
| 13 | + stackComponentId?: string; |
| 14 | +} |
| 15 | + |
| 16 | +export default class UnmountRaceScreen extends React.Component<Props, { data: string }> { |
| 17 | + static options() { |
| 18 | + return { |
| 19 | + topBar: { |
| 20 | + title: { |
| 21 | + text: 'Unmount Race', |
| 22 | + }, |
| 23 | + }, |
| 24 | + }; |
| 25 | + } |
| 26 | + |
| 27 | + state = { data: 'loading' }; |
| 28 | + private checkTimer: ReturnType<typeof setTimeout> | null = null; |
| 29 | + |
| 30 | + componentDidMount() { |
| 31 | + sharedData = 'loaded'; |
| 32 | + this.checkTimer = setTimeout(() => { |
| 33 | + this.setState({ data: sharedData ?? 'stale_unmount' }); |
| 34 | + }, 600); |
| 35 | + } |
| 36 | + |
| 37 | + componentWillUnmount() { |
| 38 | + if (this.checkTimer) { |
| 39 | + clearTimeout(this.checkTimer); |
| 40 | + } |
| 41 | + sharedData = null; |
| 42 | + } |
| 43 | + |
| 44 | + render() { |
| 45 | + return ( |
| 46 | + <Root componentId={this.props.componentId}> |
| 47 | + <View style={styles.container}> |
| 48 | + <Text testID={testIDs.UNMOUNT_RACE_DATA} style={styles.text}> |
| 49 | + {this.state.data} |
| 50 | + </Text> |
| 51 | + </View> |
| 52 | + <Button |
| 53 | + label="Pop and Re-push" |
| 54 | + testID={testIDs.POP_AND_REPUSH_BTN} |
| 55 | + onPress={this.popAndRepush} |
| 56 | + /> |
| 57 | + <Button label="Pop" testID={testIDs.POP_BTN} onPress={this.pop} /> |
| 58 | + </Root> |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + popAndRepush = () => { |
| 63 | + const stackId = this.props.stackComponentId; |
| 64 | + if (!stackId) return; |
| 65 | + Navigation.pop(this.props.componentId); |
| 66 | + Navigation.push(stackId, { |
| 67 | + component: { |
| 68 | + name: Screens.UnmountRace, |
| 69 | + passProps: { stackComponentId: stackId }, |
| 70 | + }, |
| 71 | + }); |
| 72 | + }; |
| 73 | + |
| 74 | + pop = () => Navigation.pop(this); |
| 75 | +} |
| 76 | + |
| 77 | +const styles = StyleSheet.create({ |
| 78 | + container: { padding: 20, alignItems: 'center' }, |
| 79 | + text: { fontSize: 24 }, |
| 80 | +}); |
0 commit comments