import React from 'react'; import { StyleSheet } from 'react-native'; import type { NavigatorRouteViewProps } from '../components/NavigatorRouteView'; import type { RouteViewPortal } from '../components/RouteViewPortal'; import type { NavigationObject } from '../types/NavigationObject'; import { NativeIDKeys } from '../constants/LibraryConstants'; import { RNIWrapperView } from '../native_components/RNIWrapperView'; type RouteComponentsWrapperProps = Pick & { navigation: NavigationObject; getPortalRef: () => RouteViewPortal | undefined; }; /** * This component is used to hold `NavigatorRouteView`'s navigation bar items, and the * other route-related comp. such as the route header. * * * This component needs to wrap the route component items so that they can re-render * and update when needed. * * * This component receives the route component items from `RouteViewPortal`. Whenever * `RouteViewPortal` updates, this comp. will also update, causing the nav. bar items * to re-render and update. */ export class RouteComponentsWrapper extends React.Component { private _routeViewPortalRef?: RouteViewPortal; componentDidMount(){ const props = this.props; this._routeViewPortalRef = props.getPortalRef(); }; setPortalRef = (portalRef: RouteViewPortal) => { this._routeViewPortalRef = portalRef; }; requestUpdate = () => { const props = this.props; const portalProps = this._routeViewPortalRef?.props; const hasNavBarItem = ( portalProps?.renderNavBarLeftItem != null || portalProps?.renderNavBarRightItem != null || portalProps?.renderNavBarTitleItem != null || props.renderNavBarLeftItem != null || props.renderNavBarRightItem != null || props.renderNavBarTitleItem != null ); if(hasNavBarItem){ this.forceUpdate(); }; }; render(){ const props = this.props; const portalProps = this._routeViewPortalRef?.props; const navigation = props.navigation; const navBarLeftItem = ( portalProps?.renderNavBarLeftItem?.(navigation) ?? props.renderNavBarLeftItem?.(navigation) ); const navBarRightItem = ( portalProps?.renderNavBarRightItem?.(navigation) ?? props.renderNavBarRightItem?.(navigation) ); const navBarTitleItem = ( portalProps?.renderNavBarTitleItem?.(navigation) ?? props.renderNavBarTitleItem?.(navigation) ); return( {navBarLeftItem && ( {navBarLeftItem} )} {navBarRightItem && ( {navBarRightItem} )} {navBarTitleItem && ( {navBarTitleItem} )} ); }; }; const styles = StyleSheet.create({ routeItemContainer: { position: 'absolute', overflow: 'visible', }, });