react-native-gesture-handler 1.2.1 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DrawerLayout.js +5 -4
- package/GestureButtons.js +166 -0
- package/GestureComponents.js +63 -0
- package/GestureComponents.web.js +35 -0
- package/GestureHandler.js +10 -621
- package/GestureHandlerButton.web.js +4 -12
- package/GestureHandlerPropTypes.js +45 -0
- package/Gestures.js +278 -0
- package/NativeViewGestureHandler.js +14 -0
- package/PlatformConstants.web.js +3 -1
- package/RNGestureHandler.podspec +1 -1
- package/RNGestureHandlerModule.web.js +49 -0
- package/State.js +12 -1
- package/Swipeable.js +6 -11
- package/android/build.gradle +3 -7
- package/android/lib/src/main/java/com/swmansion/gesturehandler/GestureHandlerOrchestrator.java +1 -1
- package/android/lib/src/main/java/com/swmansion/gesturehandler/PanGestureHandler.java +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.java +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.java +2 -2
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.java +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerPackage.java +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRegistry.java +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootInterface.java +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.java +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootViewManager.java +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.java +2 -2
- package/createHandler.js +46 -20
- package/createNativeWrapper.js +86 -0
- package/ios/RNGestureHandler.xcodeproj/project.pbxproj +4 -4
- package/package.json +20 -17
- package/react-native-gesture-handler.d.ts +25 -3
- package/touchables/GenericTouchable.js +3 -1
- package/touchables/TouchableHighlight.js +1 -3
- package/touchables/TouchableOpacity.web.js +2 -0
- package/touchables/TouchableWithoutFeedback.js +4 -2
- package/web/DiscreteGestureHandler.js +66 -0
- package/web/DraggingGestureHandler.js +22 -0
- package/web/Errors.js +5 -0
- package/web/FlingGestureHandler.js +137 -0
- package/web/GestureHandler.js +442 -0
- package/web/IndiscreteGestureHandler.js +33 -0
- package/web/LongPressGestureHandler.js +50 -0
- package/web/NativeViewGestureHandler.js +38 -0
- package/web/NodeManager.js +24 -0
- package/web/PanGestureHandler.js +213 -0
- package/web/PinchGestureHandler.js +24 -0
- package/web/PressGestureHandler.js +147 -0
- package/web/RotationGestureHandler.js +24 -0
- package/web/TapGestureHandler.js +160 -0
- package/web/constants.js +48 -0
- package/web/utils.js +14 -0
- package/Directions.web.js +0 -6
- package/Swipeable.web.js +0 -4
- package/createHandler.web.js +0 -205
package/DrawerLayout.js
CHANGED
@@ -78,7 +78,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
|
|
78
78
|
drawerType: 'front',
|
79
79
|
edgeWidth: 20,
|
80
80
|
minSwipeDistance: 3,
|
81
|
-
overlayColor: '
|
81
|
+
overlayColor: 'rgba(0, 0, 0, 0.7)',
|
82
82
|
drawerLockMode: 'unlocked',
|
83
83
|
};
|
84
84
|
|
@@ -110,7 +110,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
|
|
110
110
|
this._updateAnimatedEvent(props, this.state);
|
111
111
|
}
|
112
112
|
|
113
|
-
|
113
|
+
UNSAFE_componentWillUpdate(props: PropType, state: StateType) {
|
114
114
|
if (
|
115
115
|
this.props.drawerPosition !== props.drawerPosition ||
|
116
116
|
this.props.drawerWidth !== props.drawerWidth ||
|
@@ -369,7 +369,7 @@ export default class DrawerLayout extends Component<PropType, StateType> {
|
|
369
369
|
invariant(this._openValue, 'should be set');
|
370
370
|
const overlayOpacity = this._openValue.interpolate({
|
371
371
|
inputRange: [0, 1],
|
372
|
-
outputRange: [0,
|
372
|
+
outputRange: [0, 1],
|
373
373
|
extrapolate: 'clamp',
|
374
374
|
});
|
375
375
|
const dynamicOverlayStyles = {
|
@@ -450,7 +450,8 @@ export default class DrawerLayout extends Component<PropType, StateType> {
|
|
450
450
|
: styles.containerInFront,
|
451
451
|
containerStyles,
|
452
452
|
contentContainerStyle,
|
453
|
-
]}
|
453
|
+
]}
|
454
|
+
importantForAccessibility={this._drawerShown ? "no-hide-descendants" : "yes"}>
|
454
455
|
{typeof this.props.children === 'function'
|
455
456
|
? this.props.children(this._openValue)
|
456
457
|
: this.props.children}
|
@@ -0,0 +1,166 @@
|
|
1
|
+
import PropTypes from 'prop-types';
|
2
|
+
import React from 'react';
|
3
|
+
import { Animated, Platform, processColor, StyleSheet } from 'react-native';
|
4
|
+
|
5
|
+
import createNativeWrapper from './createNativeWrapper';
|
6
|
+
import GestureHandlerButton from './GestureHandlerButton';
|
7
|
+
import State from './State';
|
8
|
+
|
9
|
+
export const RawButton = createNativeWrapper(GestureHandlerButton, {
|
10
|
+
shouldCancelWhenOutside: false,
|
11
|
+
shouldActivateOnStart: false,
|
12
|
+
});
|
13
|
+
|
14
|
+
/* Buttons */
|
15
|
+
|
16
|
+
export class BaseButton extends React.Component {
|
17
|
+
static propTypes = {
|
18
|
+
...RawButton.propTypes,
|
19
|
+
onPress: PropTypes.func,
|
20
|
+
onActiveStateChange: PropTypes.func,
|
21
|
+
};
|
22
|
+
|
23
|
+
constructor(props) {
|
24
|
+
super(props);
|
25
|
+
this._lastActive = false;
|
26
|
+
}
|
27
|
+
|
28
|
+
_handleEvent = ({ nativeEvent }) => {
|
29
|
+
const { state, oldState, pointerInside } = nativeEvent;
|
30
|
+
const active = pointerInside && state === State.ACTIVE;
|
31
|
+
|
32
|
+
if (active !== this._lastActive && this.props.onActiveStateChange) {
|
33
|
+
this.props.onActiveStateChange(active);
|
34
|
+
}
|
35
|
+
|
36
|
+
if (
|
37
|
+
oldState === State.ACTIVE &&
|
38
|
+
state !== State.CANCELLED &&
|
39
|
+
this._lastActive &&
|
40
|
+
this.props.onPress
|
41
|
+
) {
|
42
|
+
this.props.onPress(active);
|
43
|
+
}
|
44
|
+
|
45
|
+
this._lastActive = active;
|
46
|
+
};
|
47
|
+
|
48
|
+
// Normally, the parent would execute it's handler first,
|
49
|
+
// then forward the event to listeners. However, here our handler
|
50
|
+
// is virtually only forwarding events to listeners, so we reverse the order
|
51
|
+
// to keep the proper order of the callbacks (from "raw" ones to "processed").
|
52
|
+
_onHandlerStateChange = e => {
|
53
|
+
this.props.onHandlerStateChange && this.props.onHandlerStateChange(e);
|
54
|
+
this._handleEvent(e);
|
55
|
+
};
|
56
|
+
|
57
|
+
_onGestureEvent = e => {
|
58
|
+
this.props.onGestureEvent && this.props.onGestureEvent(e);
|
59
|
+
this._handleEvent(e);
|
60
|
+
};
|
61
|
+
|
62
|
+
render() {
|
63
|
+
const { style, rippleColor, ...rest } = this.props;
|
64
|
+
|
65
|
+
return (
|
66
|
+
<RawButton
|
67
|
+
style={[{ overflow: 'hidden' }, style]}
|
68
|
+
rippleColor={processColor(rippleColor)}
|
69
|
+
{...rest}
|
70
|
+
onGestureEvent={this._onGestureEvent}
|
71
|
+
onHandlerStateChange={this._onHandlerStateChange}
|
72
|
+
/>
|
73
|
+
);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
const AnimatedBaseButton = Animated.createAnimatedComponent(BaseButton);
|
78
|
+
|
79
|
+
const btnStyles = StyleSheet.create({
|
80
|
+
underlay: {
|
81
|
+
position: 'absolute',
|
82
|
+
left: 0,
|
83
|
+
right: 0,
|
84
|
+
bottom: 0,
|
85
|
+
top: 0,
|
86
|
+
},
|
87
|
+
});
|
88
|
+
|
89
|
+
export class RectButton extends React.Component {
|
90
|
+
static propTypes = BaseButton.propTypes;
|
91
|
+
|
92
|
+
static defaultProps = {
|
93
|
+
activeOpacity: 0.105,
|
94
|
+
underlayColor: 'black',
|
95
|
+
};
|
96
|
+
|
97
|
+
constructor(props) {
|
98
|
+
super(props);
|
99
|
+
this._opacity = new Animated.Value(0);
|
100
|
+
}
|
101
|
+
|
102
|
+
_onActiveStateChange = active => {
|
103
|
+
if (Platform.OS !== 'android') {
|
104
|
+
this._opacity.setValue(active ? this.props.activeOpacity : 0);
|
105
|
+
}
|
106
|
+
|
107
|
+
this.props.onActiveStateChange && this.props.onActiveStateChange(active);
|
108
|
+
};
|
109
|
+
|
110
|
+
render() {
|
111
|
+
const { children, ...rest } = this.props;
|
112
|
+
|
113
|
+
return (
|
114
|
+
<BaseButton {...rest} onActiveStateChange={this._onActiveStateChange}>
|
115
|
+
<Animated.View
|
116
|
+
style={[
|
117
|
+
btnStyles.underlay,
|
118
|
+
{ opacity: this._opacity },
|
119
|
+
{ backgroundColor: this.props.underlayColor },
|
120
|
+
]}
|
121
|
+
/>
|
122
|
+
{children}
|
123
|
+
</BaseButton>
|
124
|
+
);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
export class BorderlessButton extends React.Component {
|
129
|
+
static propTypes = {
|
130
|
+
...BaseButton.propTypes,
|
131
|
+
borderless: PropTypes.bool,
|
132
|
+
};
|
133
|
+
|
134
|
+
static defaultProps = {
|
135
|
+
activeOpacity: 0.3,
|
136
|
+
borderless: true,
|
137
|
+
};
|
138
|
+
|
139
|
+
constructor(props) {
|
140
|
+
super(props);
|
141
|
+
this._opacity = new Animated.Value(1);
|
142
|
+
}
|
143
|
+
|
144
|
+
_onActiveStateChange = active => {
|
145
|
+
if (Platform.OS !== 'android') {
|
146
|
+
this._opacity.setValue(active ? this.props.activeOpacity : 1);
|
147
|
+
}
|
148
|
+
|
149
|
+
this.props.onActiveStateChange && this.props.onActiveStateChange(active);
|
150
|
+
};
|
151
|
+
|
152
|
+
render() {
|
153
|
+
const { children, style, ...rest } = this.props;
|
154
|
+
|
155
|
+
return (
|
156
|
+
<AnimatedBaseButton
|
157
|
+
{...rest}
|
158
|
+
onActiveStateChange={this._onActiveStateChange}
|
159
|
+
style={[style, Platform.OS === 'ios' && { opacity: this._opacity }]}>
|
160
|
+
{children}
|
161
|
+
</AnimatedBaseButton>
|
162
|
+
);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
export { default as PureNativeButton } from './GestureHandlerButton';
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import ReactNative from 'react-native';
|
3
|
+
|
4
|
+
import createNativeWrapper from './createNativeWrapper';
|
5
|
+
|
6
|
+
const MEMOIZED = new WeakMap();
|
7
|
+
|
8
|
+
function memoizeWrap(Component, config) {
|
9
|
+
if (Component == null) {
|
10
|
+
return null;
|
11
|
+
}
|
12
|
+
let memoized = MEMOIZED.get(Component);
|
13
|
+
if (!memoized) {
|
14
|
+
memoized = createNativeWrapper(
|
15
|
+
Component,
|
16
|
+
config
|
17
|
+
);
|
18
|
+
MEMOIZED.set(Component, memoized);
|
19
|
+
}
|
20
|
+
return memoized;
|
21
|
+
}
|
22
|
+
|
23
|
+
module.exports = {
|
24
|
+
/* RN's components */
|
25
|
+
get ScrollView() {
|
26
|
+
return memoizeWrap(ReactNative.ScrollView, {
|
27
|
+
disallowInterruption: true,
|
28
|
+
});
|
29
|
+
},
|
30
|
+
get Switch() {
|
31
|
+
return memoizeWrap(ReactNative.Switch, {
|
32
|
+
shouldCancelWhenOutside: false,
|
33
|
+
shouldActivateOnStart: true,
|
34
|
+
disallowInterruption: true,
|
35
|
+
});
|
36
|
+
},
|
37
|
+
get TextInput() {
|
38
|
+
return memoizeWrap(ReactNative.TextInput);
|
39
|
+
},
|
40
|
+
get ToolbarAndroid() {
|
41
|
+
return memoizeWrap(ReactNative.ToolbarAndroid);
|
42
|
+
},
|
43
|
+
get DrawerLayoutAndroid() {
|
44
|
+
const DrawerLayoutAndroid = memoizeWrap(ReactNative.DrawerLayoutAndroid, {
|
45
|
+
disallowInterruption: true,
|
46
|
+
});
|
47
|
+
DrawerLayoutAndroid.positions = ReactNative.DrawerLayoutAndroid.positions;
|
48
|
+
return DrawerLayoutAndroid;
|
49
|
+
},
|
50
|
+
get FlatList() {
|
51
|
+
if (!MEMOIZED.FlatList) {
|
52
|
+
const ScrollView = this.ScrollView;
|
53
|
+
MEMOIZED.FlatList = React.forwardRef((props, ref) => (
|
54
|
+
<ReactNative.FlatList
|
55
|
+
ref={ref}
|
56
|
+
{...props}
|
57
|
+
renderScrollComponent={scrollProps => <ScrollView {...scrollProps} />}
|
58
|
+
/>
|
59
|
+
));
|
60
|
+
}
|
61
|
+
return MEMOIZED.FlatList;
|
62
|
+
},
|
63
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import {
|
3
|
+
DrawerLayoutAndroid as RNDrawerLayoutAndroid,
|
4
|
+
FlatList as RNFlatList,
|
5
|
+
Switch as RNSwitch,
|
6
|
+
TextInput as RNTextInput,
|
7
|
+
ToolbarAndroid as RNToolbarAndroid,
|
8
|
+
ScrollView as RNScrollView,
|
9
|
+
} from 'react-native';
|
10
|
+
|
11
|
+
import createNativeWrapper from './createNativeWrapper';
|
12
|
+
|
13
|
+
export const ScrollView = createNativeWrapper(RNScrollView, {
|
14
|
+
disallowInterruption: true,
|
15
|
+
});
|
16
|
+
|
17
|
+
export const Switch = createNativeWrapper(RNSwitch, {
|
18
|
+
shouldCancelWhenOutside: false,
|
19
|
+
shouldActivateOnStart: true,
|
20
|
+
disallowInterruption: true,
|
21
|
+
});
|
22
|
+
export const TextInput = createNativeWrapper(RNTextInput);
|
23
|
+
export const ToolbarAndroid = createNativeWrapper(RNToolbarAndroid);
|
24
|
+
export const DrawerLayoutAndroid = createNativeWrapper(RNDrawerLayoutAndroid, {
|
25
|
+
disallowInterruption: true,
|
26
|
+
});
|
27
|
+
DrawerLayoutAndroid.positions = RNDrawerLayoutAndroid.positions;
|
28
|
+
|
29
|
+
export const FlatList = React.forwardRef((props, ref) => (
|
30
|
+
<RNFlatList
|
31
|
+
ref={ref}
|
32
|
+
{...props}
|
33
|
+
renderScrollComponent={scrollProps => <ScrollView {...scrollProps} />}
|
34
|
+
/>
|
35
|
+
));
|