mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-28 20:35:19 +08:00
fix: use theme in PlatformPressable
This commit is contained in:
@@ -22,7 +22,8 @@ export default function HeaderBackButton({
|
||||
labelVisible = Platform.OS === 'ios',
|
||||
onLabelLayout,
|
||||
onPress,
|
||||
pressColorAndroid: customPressColorAndroid,
|
||||
pressColor,
|
||||
pressOpacity,
|
||||
screenLayout,
|
||||
tintColor: customTintColor,
|
||||
titleLayout,
|
||||
@@ -31,7 +32,7 @@ export default function HeaderBackButton({
|
||||
testID,
|
||||
style,
|
||||
}: HeaderBackButtonProps) {
|
||||
const { dark, colors } = useTheme();
|
||||
const { colors } = useTheme();
|
||||
|
||||
const [initialLabelWidth, setInitialLabelWidth] = React.useState<
|
||||
undefined | number
|
||||
@@ -45,13 +46,6 @@ export default function HeaderBackButton({
|
||||
default: colors.text,
|
||||
});
|
||||
|
||||
const pressColorAndroid =
|
||||
customPressColorAndroid !== undefined
|
||||
? customPressColorAndroid
|
||||
: dark
|
||||
? 'rgba(255, 255, 255, .32)'
|
||||
: 'rgba(0, 0, 0, .32)';
|
||||
|
||||
const handleLabelLayout = (e: LayoutChangeEvent) => {
|
||||
onLabelLayout?.(e);
|
||||
|
||||
@@ -156,7 +150,8 @@ export default function HeaderBackButton({
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
testID={testID}
|
||||
onPress={disabled ? undefined : handlePress}
|
||||
pressColor={pressColorAndroid}
|
||||
pressColor={pressColor}
|
||||
pressOpacity={pressOpacity}
|
||||
android_ripple={{ borderless: true }}
|
||||
style={[styles.container, disabled && styles.disabled, style]}
|
||||
hitSlop={Platform.select({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import { Platform, Pressable, PressableProps } from 'react-native';
|
||||
import { useTheme } from '@react-navigation/native';
|
||||
|
||||
export type Props = PressableProps & {
|
||||
pressColor?: string;
|
||||
@@ -12,24 +13,30 @@ const ANDROID_SUPPORTS_RIPPLE =
|
||||
Platform.OS === 'android' && Platform.Version >= ANDROID_VERSION_LOLLIPOP;
|
||||
|
||||
/**
|
||||
* PlatformPressable provides an abstraction on top of TouchableNativeFeedback and
|
||||
* TouchableOpacity to handle platform differences.
|
||||
*
|
||||
* On Android, you can pass the props of TouchableNativeFeedback.
|
||||
* On other platforms, you can pass the props of TouchableOpacity.
|
||||
* PlatformPressable provides an abstraction on top of Pressable to handle platform differences.
|
||||
*/
|
||||
export default function PlatformPressable({
|
||||
android_ripple,
|
||||
pressColor = 'rgba(0, 0, 0, .32)',
|
||||
pressColor,
|
||||
pressOpacity,
|
||||
style,
|
||||
...rest
|
||||
}: Props) {
|
||||
const { dark } = useTheme();
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
android_ripple={
|
||||
ANDROID_SUPPORTS_RIPPLE
|
||||
? { color: pressColor, ...android_ripple }
|
||||
? {
|
||||
color:
|
||||
pressColor !== undefined
|
||||
? pressColor
|
||||
: dark
|
||||
? 'rgba(255, 255, 255, .32)'
|
||||
: 'rgba(0, 0, 0, .32)',
|
||||
...android_ripple,
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
style={({ pressed }) => [
|
||||
|
||||
@@ -127,13 +127,16 @@ export type HeaderBackButtonProps = {
|
||||
disabled?: boolean;
|
||||
/**
|
||||
* Callback to call when the button is pressed.
|
||||
* By default, this triggers `goBack`.
|
||||
*/
|
||||
onPress?: () => void;
|
||||
/**
|
||||
* Color for material ripple (Android >= 5.0 only).
|
||||
*/
|
||||
pressColorAndroid?: string;
|
||||
pressColor?: string;
|
||||
/**
|
||||
* Opacity when the button is pressed, used when ripple is not supported.
|
||||
*/
|
||||
pressOpacity?: number;
|
||||
/**
|
||||
* Function which returns a React Element to display custom image in header's back button.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user