2020-12-25 17:09:53 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { Image, Keyboard, TouchableOpacity, StyleSheet } from 'react-native';
|
2021-07-21 14:29:18 +02:00
|
|
|
import { Theme } from './themes';
|
2023-03-31 17:32:07 +02:00
|
|
|
import loc from '../loc';
|
2020-12-25 17:09:53 +01:00
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
button: {
|
|
|
|
minWidth: 40,
|
|
|
|
height: 40,
|
|
|
|
justifyContent: 'center',
|
2021-09-13 19:43:26 +02:00
|
|
|
alignItems: 'center',
|
2020-12-25 17:09:53 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-07-21 14:29:18 +02:00
|
|
|
type NavigationOptions = {
|
|
|
|
headerStyle?: {
|
|
|
|
borderBottomWidth: number;
|
|
|
|
elevation: number;
|
|
|
|
shadowOpacity?: number;
|
|
|
|
shadowOffset: { height?: number; width?: number };
|
|
|
|
};
|
|
|
|
headerTitleStyle?: {
|
|
|
|
fontWeight: string;
|
|
|
|
color: string;
|
|
|
|
};
|
2023-10-23 20:50:17 +02:00
|
|
|
headerLargeTitle?: boolean;
|
2023-12-14 19:40:43 +01:00
|
|
|
headerBackVisible?: boolean;
|
2023-10-23 03:59:16 +02:00
|
|
|
gestureEnabled?: boolean;
|
|
|
|
swipeEnabled?: boolean;
|
2024-01-13 17:28:55 +01:00
|
|
|
headerTransparent?: boolean;
|
2023-10-23 03:59:16 +02:00
|
|
|
headerHideBackButton?: boolean;
|
2021-07-21 14:29:18 +02:00
|
|
|
headerLeft?: (() => React.ReactElement) | null;
|
|
|
|
headerRight?: (() => React.ReactElement) | null;
|
|
|
|
headerBackTitleVisible?: false;
|
2024-01-21 16:09:25 +01:00
|
|
|
headerBackButtonMenuEnabled?: boolean;
|
2024-01-13 17:28:55 +01:00
|
|
|
headerShadowVisible?: boolean;
|
2021-07-21 14:29:18 +02:00
|
|
|
headerTintColor?: string;
|
|
|
|
title?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type OptionsFormatter = (options: NavigationOptions, deps: { theme: Theme; navigation: any; route: any }) => NavigationOptions;
|
|
|
|
|
|
|
|
export type NavigationOptionsGetter = (theme: Theme) => (deps: { navigation: any; route: any }) => NavigationOptions;
|
|
|
|
|
|
|
|
const navigationStyle = (
|
|
|
|
{
|
|
|
|
closeButton = false,
|
|
|
|
closeButtonFunc,
|
2024-01-21 20:59:28 +01:00
|
|
|
headerBackVisible = true,
|
2021-07-21 14:29:18 +02:00
|
|
|
...opts
|
|
|
|
}: NavigationOptions & {
|
|
|
|
closeButton?: boolean;
|
2023-04-02 02:16:00 +02:00
|
|
|
|
2021-07-21 14:29:18 +02:00
|
|
|
closeButtonFunc?: (deps: { navigation: any; route: any }) => React.ReactElement;
|
|
|
|
},
|
|
|
|
formatter: OptionsFormatter,
|
|
|
|
): NavigationOptionsGetter => {
|
2022-01-26 18:50:41 +01:00
|
|
|
return theme =>
|
|
|
|
({ navigation, route }) => {
|
|
|
|
let headerRight;
|
2024-01-21 16:09:25 +01:00
|
|
|
let headerLeft;
|
2022-01-26 18:50:41 +01:00
|
|
|
if (closeButton) {
|
|
|
|
const handleClose = closeButtonFunc
|
|
|
|
? () => closeButtonFunc({ navigation, route })
|
|
|
|
: () => {
|
|
|
|
Keyboard.dismiss();
|
|
|
|
navigation.goBack(null);
|
|
|
|
};
|
|
|
|
headerRight = () => (
|
2023-04-02 02:16:00 +02:00
|
|
|
<TouchableOpacity
|
|
|
|
accessibilityRole="button"
|
|
|
|
accessibilityLabel={loc._.close}
|
|
|
|
style={styles.button}
|
|
|
|
onPress={handleClose}
|
|
|
|
testID="NavigationCloseButton"
|
2023-03-31 17:32:07 +02:00
|
|
|
>
|
2022-01-26 18:50:41 +01:00
|
|
|
<Image source={theme.closeImage} />
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
2020-12-25 17:09:53 +01:00
|
|
|
|
2024-01-21 16:09:25 +01:00
|
|
|
// Workaround for https://github.com/BlueWallet/BlueWallet/issues/6030
|
|
|
|
if (!headerBackVisible) {
|
|
|
|
headerLeft = () => <></>;
|
|
|
|
opts.headerLeft = headerLeft;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
2022-01-26 18:50:41 +01:00
|
|
|
let options: NavigationOptions = {
|
2024-01-13 17:28:55 +01:00
|
|
|
headerShadowVisible: false,
|
2022-01-26 18:50:41 +01:00
|
|
|
headerTitleStyle: {
|
|
|
|
fontWeight: '600',
|
|
|
|
color: theme.colors.foregroundColor,
|
|
|
|
},
|
2022-10-31 13:25:26 +01:00
|
|
|
headerRight,
|
2022-01-26 18:50:41 +01:00
|
|
|
headerBackTitleVisible: false,
|
|
|
|
headerTintColor: theme.colors.foregroundColor,
|
|
|
|
...opts,
|
|
|
|
};
|
2020-12-25 17:09:53 +01:00
|
|
|
|
2022-01-26 18:50:41 +01:00
|
|
|
if (formatter) {
|
|
|
|
options = formatter(options, { theme, navigation, route });
|
|
|
|
}
|
2020-12-25 17:09:53 +01:00
|
|
|
|
2022-01-26 18:50:41 +01:00
|
|
|
return options;
|
|
|
|
};
|
2020-12-25 17:09:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default navigationStyle;
|
|
|
|
|
2021-07-21 14:29:18 +02:00
|
|
|
export const navigationStyleTx = (opts: NavigationOptions, formatter: OptionsFormatter): NavigationOptionsGetter => {
|
2022-01-26 18:50:41 +01:00
|
|
|
return theme =>
|
|
|
|
({ navigation, route }) => {
|
|
|
|
let options: NavigationOptions = {
|
|
|
|
headerStyle: {
|
|
|
|
borderBottomWidth: 0,
|
|
|
|
elevation: 0,
|
|
|
|
shadowOffset: { height: 0, width: 0 },
|
|
|
|
},
|
|
|
|
headerTitleStyle: {
|
|
|
|
fontWeight: '600',
|
|
|
|
color: theme.colors.foregroundColor,
|
|
|
|
},
|
|
|
|
// headerBackTitle: null,
|
|
|
|
headerBackTitleVisible: false,
|
|
|
|
headerTintColor: theme.colors.foregroundColor,
|
|
|
|
headerLeft: () => (
|
2023-04-02 02:16:00 +02:00
|
|
|
<TouchableOpacity
|
|
|
|
accessibilityRole="button"
|
|
|
|
accessibilityLabel={loc._.close}
|
|
|
|
style={styles.button}
|
2022-01-26 18:50:41 +01:00
|
|
|
onPress={() => {
|
|
|
|
Keyboard.dismiss();
|
|
|
|
navigation.goBack(null);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Image source={theme.closeImage} />
|
|
|
|
</TouchableOpacity>
|
|
|
|
),
|
|
|
|
...opts,
|
|
|
|
};
|
2020-12-25 17:09:53 +01:00
|
|
|
|
2022-01-26 18:50:41 +01:00
|
|
|
if (formatter) {
|
|
|
|
options = formatter(options, { theme, navigation, route });
|
|
|
|
}
|
2020-12-25 17:09:53 +01:00
|
|
|
|
2022-01-26 18:50:41 +01:00
|
|
|
return options;
|
|
|
|
};
|
2020-12-25 17:09:53 +01:00
|
|
|
};
|