//@ts-ignore import AppContainer from 'react-native/Libraries/ReactNative/AppContainer'; import { appContainerMap, pageTitleMap } from '../global'; export default function injectAppContainer() { const proto = AppContainer.prototype; if (proto.componentDidMount) { proto.componentDidMount = new Proxy(proto.componentDidMount, { apply: (target, thisArgument, argumentsList) => { const result = Reflect.apply(target, thisArgument, argumentsList); try { const props = thisArgument.props; appContainerMap.set(props.rootTag, thisArgument); } catch (e: any) { console.warn(e.message); } return result; }, }); } if (proto.componentWillUnmount) { proto.componentWillUnmount = new Proxy(proto.componentWillUnmount, { apply: (target, thisArgument, argumentsList) => { const result = Reflect.apply(target, thisArgument, argumentsList); try { // console.info('unmount!') appContainerMap.delete(thisArgument.props.rootTag); pageTitleMap.delete(thisArgument.props.rootTag); } catch (e: any) { console.warn(e.message); } return result; }, }); } }