import React, { Component } from 'react'; import { StyleSheet, Button, View, TextInput } from 'react-native'; import { Screen, ScreenStack } from 'react-native-screens'; type StackProps = { renderScreen: (key: string) => JSX.Element; }; type StackState = { stack: string[]; transitioning: number; }; const COLORS = ['azure', 'pink', 'cyan']; export class Stack extends Component { state = { stack: ['azure'], transitioning: 0, }; push(key: string) { const { stack } = this.state; this.setState({ stack: [...stack, key], transitioning: 1 }); } pop() { const { stack } = this.state; this.setState({ transitioning: 0, stack: stack.slice(0, -1) }); } remove(index: number) { const { stack } = this.state; this.setState({ stack: stack.filter((v, idx) => idx !== index) }); } removeByKey(key: string) { const { stack } = this.state; this.setState({ stack: stack.filter((v) => key !== v) }); } renderScreen = (key: string) => { return ( this.removeByKey(key)}> {this.props.renderScreen(key)} ); }; render() { const screens = this.state.stack.map(this.renderScreen); return {screens}; } } class App extends Component { stackRef = React.createRef(); renderScreen = (key: string) => { const index = COLORS.indexOf(key); const color = key; const pop = index > 0 ? () => this.stackRef.current?.pop() : null; const push = index < 2 ? () => this.stackRef.current?.push(COLORS[index + 1]) : null; const remove = index > 1 ? () => this.stackRef.current?.remove(1) : null; return ( {pop &&