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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ const BottomSheet = forwardRef<BottomSheetRef, BottomSheetProps>(
const onCloseCB = useCallback(() => {
if (shouldNavigateBack && !didNavigateBackRef.current) {
didNavigateBackRef.current = true;
navigation.goBack();
if (navigation.isFocused()) {
navigation.goBack();
} else {
Logger.log(
'[BottomSheet] navigation.goBack skipped (screen not focused)',
);
}
} else if (shouldNavigateBack && didNavigateBackRef.current) {
Logger.log('[BottomSheet] navigation.goBack skipped (duplicate close)');
}
Expand All @@ -92,14 +98,17 @@ const BottomSheet = forwardRef<BottomSheetRef, BottomSheetProps>(
// Dismiss the sheet when Android back button is pressed.
useEffect(() => {
const hardwareBackPress = () => {
if (!navigation.isFocused()) {
return false;
}
isInteractable && bottomSheetDialogRef.current?.onCloseDialog();
return true;
};
BackHandler.addEventListener('hardwareBackPress', hardwareBackPress);
return () => {
BackHandler.removeEventListener('hardwareBackPress', hardwareBackPress);
};
}, [onCloseCB, isInteractable]);
}, [onCloseCB, isInteractable, navigation]);

useImperativeHandle(ref, () => ({
onCloseBottomSheet: (callback) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jest.mock('@react-navigation/native', () => {
dangerouslyGetParent: () => ({
pop: jest.fn(),
}),
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jest.mock('@react-navigation/native', () => ({
useNavigation: () => ({
goBack: mockGoBack,
navigate: mockNavigate,
isFocused: jest.fn(() => true),
}),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jest.mock('@react-navigation/native', () => ({
useNavigation: () => ({
navigate: mockNavigate,
goBack: mockGoBack,
isFocused: () => true,
}),
}));

Expand Down
1 change: 1 addition & 0 deletions app/components/UI/DeepLinkModal/DeepLinkModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const mockGoBack = jest.fn();
(useNavigation as jest.Mock).mockReturnValue({
navigate: mockNavigate,
goBack: mockGoBack,
isFocused: jest.fn(() => true),
} as never);

describe('DeepLinkModal', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jest.mock('@react-navigation/native', () => {
useNavigation: () => ({
navigate: mockNavigate,
goBack: mockGoBack,
isFocused: jest.fn(() => true),
}),
useRoute: () => ({
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jest.mock('@react-navigation/native', () => {
useNavigation: () => ({
navigate: mockNavigate,
goBack: mockGoBack,
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jest.mock('@react-navigation/native', () => {
dangerouslyGetParent: () => ({
pop: jest.fn(),
}),
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const mockNavigation = {
goBack: jest.fn(),
setOptions: mockSetOptions,
dangerouslyGetParent: () => ({ pop: mockPop }),
isFocused: jest.fn(() => true),
};
jest.mock('@react-navigation/native', () => ({
...jest.requireActual('@react-navigation/native'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jest.mock('@react-navigation/native', () => {
goBack: mockGoBack,
reset: mockReset,
pop: mockPop,
isFocused: () => true,
dangerouslyGetParent: () => ({
pop: mockPop,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jest.mock('@react-navigation/native', () => {
navigate: mockNavigate,
goBack: mockGoBack,
dangerouslyGetParent: mockDangerouslyGetParent,
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jest.mock('@react-navigation/native', () => {
navigate: mockNavigate,
goBack: mockGoBack,
dangerouslyGetParent: mockDangerouslyGetParent,
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jest.mock('@react-navigation/native', () => {
goBack: mockGoBack,
navigate: mockNavigate,
dangerouslyGetParent: mockDangerouslyGetParent,
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('GasImpactModal', () => {
useNavigationMock.mockReturnValue({
navigate: mockNavigate,
goBack: mockGoBack,
isFocused: jest.fn(() => true),
} as unknown as ReturnType<typeof useNavigation>);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jest.mock('@react-navigation/native', () => {
useNavigation: () => ({
navigate: jest.fn(),
goBack: jest.fn(),
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ jest.mock('@react-navigation/native', () => {
useNavigation: () => ({
navigate: mockNavigate,
goBack: mockGoBack,
isFocused: jest.fn(() => true),
}),
useRoute: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jest.mock('@react-navigation/native', () => {
useNavigation: () => ({
navigate: mockedNavigate,
goBack: mockedGoBack,
isFocused: () => true,
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ exports[`AccountConnect renders correctly when merging existing CAIP-25 permissi
navigation={
{
"goBack": [MockFunction],
"isFocused": [Function],
"navigate": [MockFunction],
}
}
Expand Down Expand Up @@ -1571,6 +1572,7 @@ exports[`AccountConnect renders correctly with base request when there is no exi
navigation={
{
"goBack": [MockFunction],
"isFocused": [Function],
"navigate": [MockFunction],
}
}
Expand Down Expand Up @@ -2637,6 +2639,7 @@ exports[`AccountConnect renders correctly with request including chains and acco
navigation={
{
"goBack": [MockFunction],
"isFocused": [Function],
"navigate": [MockFunction],
}
}
Expand Down Expand Up @@ -3703,6 +3706,7 @@ exports[`AccountConnect renders correctly with request including only chains 1`]
navigation={
{
"goBack": [MockFunction],
"isFocused": [Function],
"navigate": [MockFunction],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jest.mock('@react-navigation/native', () => {
useNavigation: () => ({
navigate: mockedNavigate,
goBack: mockedGoBack,
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jest.mock('@react-navigation/native', () => ({
goBack: mockGoBack,
navigate: mockNavigate,
dispatch: jest.fn(),
isFocused: jest.fn(() => true),
}),
}));

Expand Down
1 change: 1 addition & 0 deletions app/components/Views/AssetOptions/AssetOptions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ describe('AssetOptions Component', () => {
const mockNavigation = {
navigate: jest.fn(),
goBack: jest.fn(),
isFocused: jest.fn().mockReturnValue(true),
};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jest.mock('@react-navigation/native', () => {
useNavigation: () => ({
navigate: mockNavigate,
goBack: mockGoBack,
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jest.mock('@react-navigation/native', () => {
useNavigation: () => ({
navigate: mockNavigate,
goBack: mockGoBack,
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
1 change: 1 addition & 0 deletions app/components/Views/WalletActions/WalletActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ jest.mock('@react-navigation/native', () => {
useNavigation: () => ({
navigate: mockNavigate,
goBack: mockGoBack,
isFocused: jest.fn(() => true),
}),
};
});
Expand Down
Loading