forked from microsoft/react-native-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointerButtonExample.windows.js
More file actions
119 lines (110 loc) · 2.83 KB
/
PointerButtonExample.windows.js
File metadata and controls
119 lines (110 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* @flow strict-local
* @format
*/
'use strict';
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
const React = require('react');
const {StyleSheet, Text, View} = require('react-native');
function buttonLabel(button: number): string {
switch (button) {
case 0:
return 'Left';
case 1:
return 'Middle';
case 2:
return 'Right';
case 3:
return 'X1';
case 4:
return 'X2';
default:
return `Unknown(${button})`;
}
}
function PointerDownButtonExample(): React.Node {
const [text, setText] = React.useState(
'Click the box to test pointer events',
);
return (
<View>
<Text accessible={true} testID="pointer-button-state">
{text}
</Text>
<View
accessible={true}
testID="pointer-button-target"
style={styles.targetBox}
onPointerDown={(e: any) => {
const {button, buttons} = e.nativeEvent;
setText(
`PointerDown: ${buttonLabel(button)} (button=${button}, buttons=${buttons})`,
);
}}
/>
</View>
);
}
function PointerUpButtonExample(): React.Node {
const [text, setText] = React.useState(
'Click the box to test pointer up events',
);
return (
<View>
<Text accessible={true} testID="pointer-up-button-state">
{text}
</Text>
<View
accessible={true}
testID="pointer-up-button-target"
style={styles.targetBox}
onPointerUp={(e: any) => {
const {button, buttons} = e.nativeEvent;
setText(
`PointerUp: ${buttonLabel(button)} (button=${button}, buttons=${buttons})`,
);
}}
/>
</View>
);
}
exports.displayName = 'PointerButtonExample';
exports.framework = 'React';
exports.category = 'Basic';
exports.title = 'Pointer Button';
exports.documentationURL =
'https://developer.mozilla.org/docs/Web/API/PointerEvent/button';
exports.description =
'Tests that PointerEvent.button and PointerEvent.buttons are correctly populated.';
exports.examples = [
{
title: 'onPointerDown button property',
description:
'Click the box to verify the button property on onPointerDown events.',
render: function (): React.Node {
return <PointerDownButtonExample />;
},
},
{
title: 'onPointerUp button property',
description:
'Click the box to verify the button property on onPointerUp events.',
render: function (): React.Node {
return <PointerUpButtonExample />;
},
},
] as Array<RNTesterModuleExample>;
const styles = StyleSheet.create({
targetBox: {
backgroundColor: 'magenta',
width: 200,
height: 200,
margin: 10,
borderRadius: 10,
justifyContent: 'center',
alignItems: 'center',
},
});