Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions patches/react-native-screens/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@
- Upstream PR/issue: not reported, because dropping the tint for every icon fits only a bar whose icons all arrive pre-colored, as the App's do. The disabled and focused icon colors go with it, which the App does not use.
- E/App issue: [#101169](https://github.com/Expensify/App/issues/101169)
- PR introducing patch: [#101339](https://github.com/Expensify/App/pull/101339)

### [react-native-screens+4.28.0+005+hidden-android-tab-bar-touches.patch](react-native-screens+4.28.0+005+hidden-android-tab-bar-touches.patch)

- Reason: On Android, a hidden native tab bar is set to `View.GONE`. `TabsContainer` is a `FrameLayout`, which skips `GONE` children during layout, so the bar keeps the bounds it had while visible. React Native's `TouchTargetHelper` walks native children without checking visibility, so a touch inside those stale bounds targets the hidden bar instead of the React views drawn there. On a chat, that swallowed taps on the composer's emoji and + buttons while the keyboard was closed. The touch target search skips a child whose transform is non-invertible, so the patch scales the hidden bar to zero on the Y axis and back to one when it is shown. Its layout is left alone, so the bar's height and the insets derived from it do not change.
- Upstream PR/issue: TBD
- E/App issue: [#104226](https://github.com/Expensify/App/issues/104226)
- PR introducing patch: [#104238](https://github.com/Expensify/App/pull/104238)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/gamma/tabs/appearance/TabsAppearanceApplicator.kt b/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/gamma/tabs/appearance/TabsAppearanceApplicator.kt
--- a/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/gamma/tabs/appearance/TabsAppearanceApplicator.kt
+++ b/node_modules/react-native-screens/android/src/main/java/com/swmansion/rnscreens/gamma/tabs/appearance/TabsAppearanceApplicator.kt
@@ -36,6 +36,10 @@
isTabBarHidden: Boolean,
) {
bottomNavigationView.isVisible = !isTabBarHidden
+ // A GONE child keeps the bounds it had while visible, and React Native's TouchTargetHelper does not check
+ // visibility, so the hidden bar would take touches meant for the React views drawn there. The touch target search
+ // skips a child with a non-invertible transform, so the hidden bar is scaled to zero, which leaves its layout as is.
+ bottomNavigationView.scaleY = if (isTabBarHidden) 0f else 1f
bottomNavigationView.setBackgroundColor(
tabBarAppearance?.tabBarBackgroundColor
?: resolveColorAttr(context, R.attr.colorSurfaceContainer),
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
diff --git a/node_modules/@react-navigation/bottom-tabs/lib/module/unstable/NativeBottomTabView.native.js b/node_modules/@react-navigation/bottom-tabs/lib/module/unstable/NativeBottomTabView.native.js
index 5a152a3d182..d2d69feda98 100644
--- a/node_modules/@react-navigation/bottom-tabs/lib/module/unstable/NativeBottomTabView.native.js
+++ b/node_modules/@react-navigation/bottom-tabs/lib/module/unstable/NativeBottomTabView.native.js
@@ -39,6 +39,10 @@ export function NativeBottomTabView({
// Derived from the history rather than remembered, so a route that became hidden since it was focused is skipped.
const isRouteKeyVisible = key => state.routes.some(route => route.key === key && !isRouteHidden(route));
const nativeSelectedRouteKey = isFocusedRouteHidden ? state.history.findLast(entry => isRouteKeyVisible(entry.key))?.key ?? state.routes.find(route => !isRouteHidden(route))?.key ?? focusedRouteKey : focusedRouteKey;
+ // Native tabs are identified by route name, which survives a route getting a new key. Keyed by route key, a re-keyed
+ // route replaces its native tab, and Android never removes the old one, so the bar shows the tab twice.
+ const getRouteForScreenKey = screenKey => state.routes.find(route => route.name === screenKey);
+ const nativeSelectedScreenKey = state.routes.find(route => route.key === nativeSelectedRouteKey)?.name ?? nativeSelectedRouteKey;
// Hidden routes stay mounted once visited, the same as the native tabs.
const visitedHiddenRouteKeysRef = React.useRef(new Set());
if (isFocusedRouteHidden) {
@@ -46,7 +50,7 @@ export function NativeBottomTabView({
}
const [nativeState, dispatch] = React.useReducer(reducer, {
confirmed: {
- routeKey: nativeSelectedRouteKey,
+ routeKey: nativeSelectedScreenKey,
provenance: 0
}
});
@@ -89,7 +93,7 @@ export function NativeBottomTabView({
routeKey: selectedScreenKey,
provenance
};
- const route = state.routes.find(route => route.key === selectedScreenKey);
+ const route = getRouteForScreenKey(selectedScreenKey);
if (!route) {
console.error(`Received 'tabSelected' for route that doesn't exist: ${selectedScreenKey}`);
return;
@@ -121,7 +125,7 @@ export function NativeBottomTabView({
routeKey: selectedScreenKey,
provenance
};
- const route = state.routes.find(route => route.key === selectedScreenKey);
+ const route = getRouteForScreenKey(selectedScreenKey);
if (!route) {
console.error(`Received 'tabSelectionRejected' for route that doesn't exist: ${selectedScreenKey}`);
return;
@@ -150,7 +154,7 @@ export function NativeBottomTabView({
});
navigation.emit({
type: 'tabPress',
- target: preventedScreenKey
+ target: getRouteForScreenKey(preventedScreenKey)?.key ?? preventedScreenKey
});
};
const currentOptions = descriptors[state.routes[state.index].key]?.options;
@@ -204,7 +208,7 @@ export function NativeBottomTabView({
return /*#__PURE__*/_jsxs(SafeAreaProviderCompat, {
children: [/*#__PURE__*/_jsx(Tabs.Host, {
navStateRequest: {
- selectedScreenKey: nativeSelectedRouteKey,
+ selectedScreenKey: nativeSelectedScreenKey,
baseProvenance: nativeState.confirmed.provenance
},
rejectStaleNavStateUpdates: true,
@@ -302,7 +306,7 @@ export function NativeBottomTabView({
closing: true,
route
}),
- screenKey: route.key,
+ screenKey: route.name,
preventNativeSelection: tabBarSelectionEnabled === false,
badgeValue: tabBarBadge?.toString(),
title: tabTitle,
@@ -370,6 +374,7 @@ export function NativeBottomTabView({
},
overrideScrollViewContentInsetAdjustmentBehavior
},
+ // Keyed by route key, so a re-keyed route still remounts its content inside the same native tab.
children: /*#__PURE__*/_jsx(Deferred, {
lazy: lazy,
visible: isFocused || isPreloaded,
@@ -383,8 +388,8 @@ export function NativeBottomTabView({
children: render()
})
})
- })
- }, route.key);
+ }, route.key)
+ }, route.name);
})
}, "native-tabs-host"), ...state.routes.map((route, index) => {
if (!isRouteHidden(route) || !visitedHiddenRouteKeysRef.current.has(route.key)) {
8 changes: 8 additions & 0 deletions patches/react-navigation/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
- PR Introducing Patch: [#101339](https://github.com/Expensify/App/pull/101339)
- PR Updating Patch: N/A

### [@react-navigation+bottom-tabs+7.19.2+004+stable-native-tab-identity.patch](@react-navigation+bottom-tabs+7.19.2+004+stable-native-tab-identity.patch)

- Reason: Identifies each native tab by its route name instead of its route key. The App gives the focused tab route a new key on purpose when it pre-inserts a screen under the RHP (`markFocusedTabRouteForRemount` in `GetStateForActionHandlers.ts`, #90985), so the split navigator remounts without a push-transition flash. Keyed by route key, that new key replaced the whole `Tabs.Screen`. Android never removes the old one: `TabsHostViewManager` does not override `getChildAt`/`getChildCount`, so Fabric's `removeViewAt` finds no child at that index ("view already removed from parent!") and skips `TabsHost.unmountReactSubviewAt`, while the insert goes through. The bar then shows the tab twice, and the stale copy opens a blank page. With this patch the native tab (`key`, `screenKey`, `navStateRequest.selectedScreenKey` and the selection events) uses the route name, which stays the same, and only the tab's content is keyed by the route key, so a re-keyed route still remounts its content inside the same native tab. **Remove this patch** once react-native-screens removes Android tabs correctly and React Navigation's native tab view no longer recreates a tab when its route key changes.
- Upstream PR/issue: not reported yet. The Android removal bug belongs to react-native-screens (`TabsHostViewManager`).
- E/App issue: [#104230](https://github.com/Expensify/App/issues/104230), [#104233](https://github.com/Expensify/App/issues/104233)
- PR Introducing Patch: [#104238](https://github.com/Expensify/App/pull/104238)
- PR Updating Patch: N/A

### Removed patches

- `@react-navigation+native+7.1.33+003+increase-history-go-popstate-fallback-timeout.patch` was dropped: upstream raised the `createMemoryHistory.go()` fallback timeout from 100ms to 1000ms in 7.3.18 (https://github.com/react-navigation/react-navigation/pull/13217), with the same Firefox rationale as our patch. Original context: [#94571](https://github.com/Expensify/App/issues/94571) / [#95980](https://github.com/Expensify/App/pull/95980), upstream issue https://github.com/react-navigation/react-navigation/issues/11145.
Expand Down
144 changes: 144 additions & 0 deletions tests/unit/NativeBottomTabViewTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import {act, render} from '@testing-library/react-native';

import type {ParamListBase, TabNavigationState} from '@react-navigation/native';

import {NativeBottomTabView} from '@react-navigation/bottom-tabs/unstable';
import {DefaultTheme, ThemeProvider} from '@react-navigation/native';
import React, {useEffect} from 'react';

type NativeBottomTabViewProps = Parameters<typeof NativeBottomTabView>[0];

type MockTabsHostProps = {
navStateRequest: {selectedScreenKey: string};
onTabSelected: (event: {nativeEvent: {selectedScreenKey: string; provenance: number; actionOrigin: string}}) => void;
children: React.ReactNode;
};

type MockTabsScreenProps = {
screenKey: string;
children: React.ReactNode;
};

// The published types describe the web stub, which renders nothing. Jest resolves the native view.
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const NativeTabView = NativeBottomTabView as unknown as React.ComponentType<NativeBottomTabViewProps>;

// Each mounted native tab and each mounted tab content, in mount order
const mockNativeTabMounts: string[] = [];
const contentMounts: string[] = [];
let mockLatestHostProps: MockTabsHostProps | undefined;

jest.mock('react-native-screens', () => {
const {useEffect: mockUseEffect} = jest.requireActual<typeof React>('react');

function Host(props: MockTabsHostProps) {
mockLatestHostProps = props;
return props.children;
}

function Screen({screenKey, children}: MockTabsScreenProps) {
mockUseEffect(() => {
mockNativeTabMounts.push(screenKey);
}, []);
return children;
}

return {Tabs: {Host, Screen}};
});

function TabContent({routeKey}: {routeKey: string}) {
useEffect(() => {
contentMounts.push(routeKey);
}, [routeKey]);
return null;
}

function buildTabState(inboxKey: string): TabNavigationState<ParamListBase> {
return {
type: 'tab',
key: 'tab',
index: 0,
stale: false,
routeNames: ['Inbox', 'Spend'],
routes: [
{name: 'Inbox', key: inboxKey},
{name: 'Spend', key: 'Spend-key'},
],
history: [{type: 'route', key: inboxKey}],
preloadedRouteKeys: [],
};
}

function buildNavigation() {
return {dispatch: jest.fn(), emit: jest.fn(), getState: jest.fn()};
}

function buildDescriptors(state: TabNavigationState<ParamListBase>): NativeBottomTabViewProps['descriptors'] {
const descriptors = Object.fromEntries(
state.routes.map((route) => [
route.key,
{
route,
options: {},
navigation: {},
render: () => <TabContent routeKey={route.key} />,
},
]),
);
// The view reads only the fields built above.
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return descriptors as unknown as NativeBottomTabViewProps['descriptors'];
}

function renderTabView(state: TabNavigationState<ParamListBase>, navigation: ReturnType<typeof buildNavigation>) {
return (
<ThemeProvider value={DefaultTheme}>
<NativeTabView
state={state}
// The view calls only the navigation methods the mock provides.
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
navigation={navigation as unknown as NativeBottomTabViewProps['navigation']}
descriptors={buildDescriptors(state)}
/>
</ThemeProvider>
);
}

describe('NativeBottomTabView', () => {
beforeEach(() => {
mockNativeTabMounts.length = 0;
contentMounts.length = 0;
mockLatestHostProps = undefined;
});

it('keeps the native tab when the focused route gets a new key, and remounts only its content', () => {
// Given the Inbox tab focused under a native tab bar
const navigation = buildNavigation();
const {rerender} = render(renderTabView(buildTabState('Inbox-key-1'), navigation));

// When the Inbox route gets a new key, as the pre-insert under the RHP does to remount it without a push flash (#90985)
rerender(renderTabView(buildTabState('Inbox-key-2'), navigation));

// Then no native tab is mounted again, since Android never removes the replaced one and would show Inbox twice
expect(mockNativeTabMounts).toEqual(['Inbox', 'Spend']);
// And the Inbox content still remounts under its new key, so the remount the new key asks for still happens
expect(contentMounts.filter((routeKey) => routeKey.startsWith('Inbox'))).toEqual(['Inbox-key-1', 'Inbox-key-2']);
// And native is asked to select the tab by its route name, which did not change
expect(mockLatestHostProps?.navStateRequest.selectedScreenKey).toBe('Inbox');
});

it('switches to the route whose name native reports as selected', () => {
// Given the Inbox tab focused under a native tab bar
const navigation = buildNavigation();
render(renderTabView(buildTabState('Inbox-key-1'), navigation));

// When the user selects the Spend tab natively, which reports the tab by its route name
act(() => {
mockLatestHostProps?.onTabSelected({nativeEvent: {selectedScreenKey: 'Spend', provenance: 1, actionOrigin: 'user'}});
});

// Then JS presses and navigates to that route, so JS follows native instead of dropping the selection
expect(navigation.emit).toHaveBeenCalledWith({type: 'tabPress', target: 'Spend-key'});
expect(navigation.dispatch).toHaveBeenCalledWith(expect.objectContaining({type: 'NAVIGATE', payload: expect.objectContaining({name: 'Spend'}), target: 'tab'}));
});
});
Loading