Skip to content

Commit 68f3fb2

Browse files
lunaleapsfacebook-github-bot
authored andcommitted
Add many pointers example
Summary: Changelog: [Internal] - Add a display example for offset of many pointers Reviewed By: mdvacca Differential Revision: D39736111 fbshipit-source-id: 1fb3f1037d7e743ae1a383a4f4ee876e32da4a6a
1 parent 7f1729a commit 68f3fb2

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
import * as React from 'react';
12+
import {View, Text, StyleSheet} from 'react-native';
13+
import type {RNTesterModuleExample} from '../../../types/RNTesterTypes';
14+
import type {PointerEvent} from 'react-native/Libraries/Types/CoreEventTypes';
15+
16+
const styles = StyleSheet.create({
17+
container: {height: '30%', width: '100%', backgroundColor: 'black'},
18+
properties: {},
19+
property: {borderWidth: 1, margin: 10},
20+
});
21+
22+
function ManyPointersPropertiesExample(): React.Node {
23+
const [data, setData] = React.useState({});
24+
const onPointerMove = (event: PointerEvent) => {
25+
const pointerId = event.nativeEvent.pointerId;
26+
setData({...data, [pointerId]: event.nativeEvent});
27+
};
28+
29+
return (
30+
<>
31+
<View style={styles.container} onPointerMove={onPointerMove} />
32+
<View style={styles.properties}>
33+
{Object.entries(data).map(
34+
//$FlowFixMe can't supply generic for Object.entries
35+
([key, evt]: [string, PointerEvent['nativeEvent']]) => (
36+
<View style={styles.property} key={key}>
37+
<Text>PointerID: {evt.pointerId}</Text>
38+
<Text>
39+
Offset: [{evt.offsetX.toPrecision(3)},{' '}
40+
{evt.offsetY.toPrecision(3)}]
41+
</Text>
42+
<Text>
43+
Coordinates: [{evt.clientX.toPrecision(3)},{' '}
44+
{evt.clientY.toPrecision(3)}]
45+
</Text>
46+
<Text>Button: {evt.button}</Text>
47+
<Text>Pressure: {evt.pressure}</Text>
48+
</View>
49+
),
50+
)}
51+
</View>
52+
</>
53+
);
54+
}
55+
56+
export default ({
57+
name: 'many_pointers_properties_example',
58+
description: 'Display of properties for multiple pointers',
59+
title: 'Display Properties of many pointers',
60+
render(): React.Node {
61+
return <ManyPointersPropertiesExample />;
62+
},
63+
}: RNTesterModuleExample);

packages/rn-tester/js/examples/Experimental/W3CPointerEventsExample.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import PointerEventPointerMoveAcross from './W3CPointerEventPlatformTests/Pointe
2222
import PointerEventPointerMoveEventOrder from './W3CPointerEventPlatformTests/PointerEventPointerMoveEventOrder';
2323
import PointerEventPointerMoveBetween from './W3CPointerEventPlatformTests/PointerEventPointerMoveBetween';
2424
import EventfulView from './W3CPointerEventsEventfulView';
25+
import ManyPointersPropertiesExample from './Compatibility/ManyPointersPropertiesExample';
2526

2627
function AbsoluteChildExample({log}: {log: string => void}) {
2728
return (
@@ -231,5 +232,6 @@ export default {
231232
},
232233
CompatibilityAnimatedPointerMove,
233234
CompatibilityNativeGestureHandling,
235+
ManyPointersPropertiesExample,
234236
],
235237
};

0 commit comments

Comments
 (0)