一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
67 行
1.8 KiB
TypeScript
67 行
1.8 KiB
TypeScript
import * as React from 'react';
|
|
import { useCallback, useMemo, useRef } from 'react';
|
|
import { Animated, StyleSheet, Pressable, ViewProps, PressableProps } from 'react-native';
|
|
|
|
interface Props extends PressableProps {
|
|
// Nodes that need to change opacity but shouldn't be included in the main touchable
|
|
beforePressable: React.ReactNode;
|
|
// Children of the main pressable
|
|
children: React.ReactNode;
|
|
onPress: ()=> void;
|
|
|
|
containerProps?: ViewProps;
|
|
}
|
|
|
|
// A TouchableOpacity that can contain multiple pressable items still within the region that
|
|
// changes opacity
|
|
const MultiTouchableOpacity: React.FC<Props> = ({ beforePressable, children, onPress, containerProps = {}, ...pressableProps }) => {
|
|
// See https://blog.logrocket.com/react-native-touchable-vs-pressable-components/
|
|
// for more about animating Pressable buttons.
|
|
const fadeAnim = useRef(new Animated.Value(1)).current;
|
|
|
|
const animationDuration = 100; // ms
|
|
const onPressIn = useCallback(() => {
|
|
// Fade out.
|
|
Animated.timing(fadeAnim, {
|
|
toValue: 0.5,
|
|
duration: animationDuration,
|
|
useNativeDriver: true,
|
|
}).start();
|
|
}, [fadeAnim]);
|
|
const onPressOut = useCallback(() => {
|
|
// Fade in.
|
|
Animated.timing(fadeAnim, {
|
|
toValue: 1,
|
|
duration: animationDuration,
|
|
useNativeDriver: true,
|
|
}).start();
|
|
}, [fadeAnim]);
|
|
|
|
const button = (
|
|
<Pressable
|
|
accessibilityRole='button'
|
|
{...pressableProps}
|
|
onPress={onPress}
|
|
onPressIn={onPressIn}
|
|
onPressOut={onPressOut}
|
|
>
|
|
{children}
|
|
</Pressable>
|
|
);
|
|
|
|
const styles = useMemo(() => {
|
|
return StyleSheet.create({
|
|
container: { opacity: fadeAnim },
|
|
});
|
|
}, [fadeAnim]);
|
|
|
|
return (
|
|
<Animated.View {...containerProps} style={[styles.container, containerProps.style]}>
|
|
{beforePressable}
|
|
{button}
|
|
</Animated.View>
|
|
);
|
|
};
|
|
|
|
export default MultiTouchableOpacity;
|