Skip to content

Commit ad2f98d

Browse files
Simekfacebook-github-bot
authored andcommitted
mark 'force' as optional property of PressEvent object (#29006)
Summary: Refs: * https://github.com/facebook/react-native/blob/master/React/Fabric/RCTSurfaceTouchHandler.mm#L93 * https://github.com/facebook/react-native/blob/master/RNTester/js/examples/Pressable/PressableExample.js#L25 According to the current implementation `force` will be returned only on `iOS` platform, only on the devices which have a hardware 3D touch capabilities. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [General] [Fixed] - mark `force` as an optional property of the PressEvent object Pull Request resolved: #29006 Test Plan: Go CI! Reviewed By: cpojer Differential Revision: D21797241 Pulled By: TheSavior fbshipit-source-id: e66be6958a2251bc8585e87e6bad54484a067949
1 parent f29238c commit ad2f98d

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Libraries/Types/CoreEventTypes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export type TextLayoutEvent = SyntheticEvent<
8888
export type PressEvent = ResponderSyntheticEvent<
8989
$ReadOnly<{|
9090
changedTouches: $ReadOnlyArray<$PropertyType<PressEvent, 'nativeEvent'>>,
91-
force: number,
91+
force?: number,
9292
identifier: number,
9393
locationX: number,
9494
locationY: number,

RNTester/js/examples/Pressable/PressableExample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function ForceTouchExample() {
167167
style={styles.wrapper}
168168
testID="pressable_3dtouch_button"
169169
onStartShouldSetResponder={() => true}
170-
onResponderMove={event => setForce(event.nativeEvent.force)}
170+
onResponderMove={event => setForce(event.nativeEvent?.force || 1)}
171171
onResponderRelease={event => setForce(0)}>
172172
<Text style={styles.button}>Press Me</Text>
173173
</View>

0 commit comments

Comments
 (0)