Skip to content

Commit

Permalink
fix: crashes on all platforms except android
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillzyusko committed Nov 25, 2024
1 parent f95db58 commit 983c325
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
8 changes: 1 addition & 7 deletions __mocks__/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as ReactNative from 'react-native';
import type StartupTimer from '@libs/StartupTimer/types';

const {BootSplash, RNNavBarManager} = ReactNative.NativeModules;
const {BootSplash} = ReactNative.NativeModules;

jest.doMock('react-native', () => {
let url = 'https://new.expensify.com/';
Expand Down Expand Up @@ -31,9 +31,6 @@ jest.doMock('react-native', () => {
navigationBarHeight: number;
};
StartupTimer: StartupTimer;
RNNavBarManager: typeof ReactNative.NativeModules & {
setButtonStyle: typeof RNNavBarManager.setButtonStyle;
};
};
Linking: typeof ReactNative.Linking & {
setInitialURL: (newUrl: string) => void;
Expand All @@ -53,9 +50,6 @@ jest.doMock('react-native', () => {
navigationBarHeight: 0,
},
StartupTimer: {stop: jest.fn()},
RNNavBarManager: {
setButtonStyle: jest.fn(),
},
},
Linking: {
...ReactNative.Linking,
Expand Down
11 changes: 11 additions & 0 deletions src/libs/NavBarManager/index.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {NativeModules} from 'react-native';
import type StartupTimer from './types';
import type {NavBarButtonStyle} from './types';

const navBarManager: StartupTimer = {
setButtonStyle: (style: NavBarButtonStyle) => {
NativeModules.RNNavBarManager.setButtonStyle(style);
},
};

export default navBarManager;
7 changes: 7 additions & 0 deletions src/libs/NavBarManager/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type NavBarManager from './types';

const navBarManager: NavBarManager = {
setButtonStyle: () => {},
};

export default navBarManager;
8 changes: 8 additions & 0 deletions src/libs/NavBarManager/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type NavBarButtonStyle = 'light' | 'dark';

type NavBarManager = {
setButtonStyle: (style: NavBarButtonStyle) => void;
};

export default NavBarManager;
export type {NavBarButtonStyle};
7 changes: 3 additions & 4 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {READ_COMMANDS} from '@libs/API/types';
import HttpUtils from '@libs/HttpUtils';
import KeyboardShortcut from '@libs/KeyboardShortcut';
import Log from '@libs/Log';
import NavBarManager from '@libs/NavBarManager';
import getCurrentUrl from '@libs/Navigation/currentUrl';
import getOnboardingModalScreenOptions from '@libs/Navigation/getOnboardingModalScreenOptions';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -71,8 +72,6 @@ import OnboardingModalNavigator from './Navigators/OnboardingModalNavigator';
import RightModalNavigator from './Navigators/RightModalNavigator';
import WelcomeVideoModalNavigator from './Navigators/WelcomeVideoModalNavigator';

const {RNNavBarManager} = NativeModules;

type AuthScreensProps = {
/** Session of currently logged in user */
session: OnyxEntry<OnyxTypes.Session>;
Expand Down Expand Up @@ -259,10 +258,10 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
});

useEffect(() => {
RNNavBarManager.setButtonStyle(theme.navigationBarButtonsStyle);
NavBarManager.setButtonStyle(theme.navigationBarButtonsStyle);

return () => {
RNNavBarManager.setButtonStyle(CONST.NAVIGATION_BAR_BUTTONS_STYLE.LIGHT);
NavBarManager.setButtonStyle(CONST.NAVIGATION_BAR_BUTTONS_STYLE.LIGHT);
};
}, [theme]);

Expand Down
3 changes: 2 additions & 1 deletion src/styles/theme/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {ValueOf} from 'type-fest';
import type {NavBarButtonStyle} from '@libs/NavBarManager/types';
import type CONST from '@src/CONST';
import type {ColorScheme, StatusBarStyle} from '..';

Expand Down Expand Up @@ -106,7 +107,7 @@ type ThemeColors = {
// Therefore, we need to define specific themes for these elements
// e.g. the StatusBar displays either "light-content" or "dark-content" based on the theme
statusBarStyle: StatusBarStyle;
navigationBarButtonsStyle: 'dark' | 'light';
navigationBarButtonsStyle: NavBarButtonStyle;
colorScheme: ColorScheme;
};

Expand Down

0 comments on commit 983c325

Please sign in to comment.