-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathstateDefinitions.ts
More file actions
149 lines (141 loc) · 3.65 KB
/
stateDefinitions.ts
File metadata and controls
149 lines (141 loc) · 3.65 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { Platform } from 'react-native';
import { PressableEvent } from './PressableProps';
import { StateDefinition } from './StateMachine';
import { isScreenReaderEnabled } from '../../utils';
export enum StateMachineEvent {
NATIVE_BEGIN = 'nativeBegin',
NATIVE_START = 'nativeStart',
FINALIZE = 'finalize',
LONG_PRESS_TOUCHES_DOWN = 'longPressTouchesDown',
CANCEL = 'cancel',
}
function getAndroidStatesConfig(
handlePressIn: (event: PressableEvent) => void,
handlePressOut: (event: PressableEvent) => void
) {
return [
{
eventName: StateMachineEvent.NATIVE_BEGIN,
},
{
eventName: StateMachineEvent.LONG_PRESS_TOUCHES_DOWN,
callback: handlePressIn,
},
{
eventName: StateMachineEvent.FINALIZE,
callback: handlePressOut,
},
];
}
function getAndroidAccessibilityStatesConfig(
handlePressIn: (event: PressableEvent) => void,
handlePressOut: (event: PressableEvent) => void
) {
return [
{
eventName: StateMachineEvent.LONG_PRESS_TOUCHES_DOWN,
callback: handlePressIn,
},
{
eventName: StateMachineEvent.NATIVE_BEGIN,
},
{
eventName: StateMachineEvent.FINALIZE,
callback: handlePressOut,
},
];
}
function getIosStatesConfig(
handlePressIn: (event: PressableEvent) => void,
handlePressOut: (event: PressableEvent) => void
) {
return [
{
eventName: StateMachineEvent.LONG_PRESS_TOUCHES_DOWN,
},
{
eventName: StateMachineEvent.NATIVE_START,
callback: handlePressIn,
},
{
eventName: StateMachineEvent.FINALIZE,
callback: handlePressOut,
},
];
}
function getWebStatesConfig(
handlePressIn: (event: PressableEvent) => void,
handlePressOut: (event: PressableEvent) => void
) {
return [
{
eventName: StateMachineEvent.NATIVE_BEGIN,
},
{
eventName: StateMachineEvent.NATIVE_START,
},
{
eventName: StateMachineEvent.LONG_PRESS_TOUCHES_DOWN,
callback: handlePressIn,
},
{
eventName: StateMachineEvent.FINALIZE,
callback: handlePressOut,
},
];
}
function getMacosStatesConfig(
handlePressIn: (event: PressableEvent) => void,
handlePressOut: (event: PressableEvent) => void
) {
return [
{
eventName: StateMachineEvent.LONG_PRESS_TOUCHES_DOWN,
},
{
eventName: StateMachineEvent.NATIVE_BEGIN,
callback: handlePressIn,
},
{
eventName: StateMachineEvent.NATIVE_START,
},
{
eventName: StateMachineEvent.FINALIZE,
callback: handlePressOut,
},
];
}
function getUniversalStatesConfig(
handlePressIn: (event: PressableEvent) => void,
handlePressOut: (event: PressableEvent) => void
) {
return [
{
eventName: StateMachineEvent.FINALIZE,
callback: (event: PressableEvent) => {
handlePressIn(event);
handlePressOut(event);
},
},
];
}
export function getStatesConfig(
handlePressIn: (event: PressableEvent) => void,
handlePressOut: (event: PressableEvent) => void
): StateDefinition[] {
if (Platform.OS === 'android') {
if (isScreenReaderEnabled()) {
return getAndroidAccessibilityStatesConfig(handlePressIn, handlePressOut);
}
return getAndroidStatesConfig(handlePressIn, handlePressOut);
} else if (Platform.OS === 'ios') {
return getIosStatesConfig(handlePressIn, handlePressOut);
} else if (Platform.OS === 'web') {
return getWebStatesConfig(handlePressIn, handlePressOut);
} else if (Platform.OS === 'macos') {
return getMacosStatesConfig(handlePressIn, handlePressOut);
} else {
// Unknown platform - using minimal universal setup.
return getUniversalStatesConfig(handlePressIn, handlePressOut);
}
}