mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
1977dd6596
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51554 Sorts pragma directives file headers in React Native. Changelog: [Internal] Reviewed By: SamChou19815 Differential Revision: D75264593 fbshipit-source-id: 9e4b253dd0fc94dc2fc469d7114b93a8aae305f4
108 lines
2.9 KiB
JavaScript
108 lines
2.9 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow strict-local
|
|
* @format
|
|
*/
|
|
|
|
import type {RNTesterModuleExample} from '../../../types/RNTesterTypes';
|
|
|
|
import ToggleNativeDriver from '../../Animated/utils/ToggleNativeDriver';
|
|
import * as React from 'react';
|
|
import {useRef, useState} from 'react';
|
|
import {Animated, StyleSheet, Text} from 'react-native';
|
|
|
|
const WIDTH = 200;
|
|
const HEIGHT = 250;
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
backgroundColor: 'black',
|
|
marginTop: 20,
|
|
width: WIDTH,
|
|
height: HEIGHT,
|
|
alignSelf: 'center',
|
|
},
|
|
text: {
|
|
color: 'white',
|
|
position: 'absolute',
|
|
top: HEIGHT / 2,
|
|
},
|
|
animatingBox: {
|
|
backgroundColor: 'blue',
|
|
width: 1,
|
|
height: 1,
|
|
},
|
|
});
|
|
|
|
function CompatibilityAnimatedPointerMove(): React.Node {
|
|
const xCoord = useRef(new Animated.Value(0)).current;
|
|
const yCoord = useRef(new Animated.Value(0)).current;
|
|
const [useNativeDriver, setUseNativeDriver] = useState(true);
|
|
|
|
return (
|
|
<>
|
|
<ToggleNativeDriver
|
|
style={{paddingHorizontal: 30}}
|
|
value={useNativeDriver}
|
|
onValueChange={setUseNativeDriver}
|
|
/>
|
|
<Animated.View
|
|
onPointerMove={Animated.event(
|
|
[{nativeEvent: {offsetX: xCoord, offsetY: yCoord}}],
|
|
{useNativeDriver},
|
|
)}
|
|
pointerEvents="box-only"
|
|
style={styles.container}>
|
|
<Text style={styles.text}>Move pointer over me</Text>
|
|
<Animated.View
|
|
style={{
|
|
backgroundColor: 'blue',
|
|
width: 1,
|
|
height: 1,
|
|
transform: [
|
|
{
|
|
translateX: xCoord.interpolate({
|
|
inputRange: [0, WIDTH],
|
|
outputRange: ([0, WIDTH / 2]: number[]),
|
|
}),
|
|
},
|
|
{
|
|
translateY: yCoord.interpolate({
|
|
inputRange: [0, HEIGHT],
|
|
outputRange: ([0, HEIGHT / 2]: number[]),
|
|
}),
|
|
},
|
|
{
|
|
scaleX: xCoord.interpolate({
|
|
inputRange: [0, WIDTH],
|
|
outputRange: ([0, WIDTH]: number[]),
|
|
}),
|
|
},
|
|
{
|
|
scaleY: yCoord.interpolate({
|
|
inputRange: [0, HEIGHT],
|
|
outputRange: ([0, HEIGHT]: number[]),
|
|
}),
|
|
},
|
|
],
|
|
}}
|
|
/>
|
|
</Animated.View>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default ({
|
|
name: 'compatibility_animatedevent_pointer_move',
|
|
description:
|
|
'An AnimatedEvent example on onPointerMove. The blue box should scale to pointer event offset values within black box',
|
|
title: 'AnimatedEvent with pointermove',
|
|
render(): React.Node {
|
|
return <CompatibilityAnimatedPointerMove />;
|
|
},
|
|
}: RNTesterModuleExample);
|