Skip to content

Commit

Permalink
Add plumbing/boilerplate for an iOS implementation of the click eve…
Browse files Browse the repository at this point in the history
…nt (facebook#36615)

Summary:
Pull Request resolved: facebook#36615

Changelog: [Internal] - Add plumbing/boilerplate for an iOS implementation of the `click` event

This diff simply adds the boilerplate necessary to hook up a click event to the fabric iOS touch handler. This diff does not contain any actual implementation of the click's behavior as that will occur in future diffs.

Reviewed By: necolas

Differential Revision: D43129366

fbshipit-source-id: 71488b893c789d21c833533471745275062c0730
  • Loading branch information
vincentriemer authored and facebook-github-bot committed Apr 5, 2023
1 parent 9bb7165 commit 54a6922
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type MouseEventProps = $ReadOnly<{|

// Experimental/Work in Progress Pointer Event Callbacks (not yet ready for use)
type PointerEventProps = $ReadOnly<{|
onClick?: ?(event: PointerEvent) => void,
onClickCapture?: ?(event: PointerEvent) => void,
onPointerEnter?: ?(event: PointerEvent) => void,
onPointerEnterCapture?: ?(event: PointerEvent) => void,
onPointerLeave?: ?(event: PointerEvent) => void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ const bubblingEventTypes = {
},

// Experimental/Work in Progress Pointer Events (not yet ready for use)
topClick: {
phasedRegistrationNames: {
captured: 'onClickCapture',
bubbled: 'onClick',
},
},
topPointerCancel: {
phasedRegistrationNames: {
captured: 'onPointerCancelCapture',
Expand Down Expand Up @@ -350,6 +356,7 @@ const validAttributesForEventProps = ConditionallyIgnoredEventHandlers({
onTouchCancel: true,

// Pointer events
onClick: true,
onPointerUp: true,
onPointerDown: true,
onPointerCancel: true,
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native/Libraries/Text/Text/RCTTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ NS_ASSUME_NONNULL_BEGIN
contentFrame:(CGRect)contentFrame
descendantViews:(NSArray<UIView *> *)descendantViews;

/**
* (Experimental and unused for Paper) Pointer event handlers.
*/
@property (nonatomic, assign) RCTBubblingEventBlock onClick;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTComponent.h>

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface RCTVirtualTextView : UIView

/**
* (Experimental and unused for Paper) Pointer event handlers.
*/
@property (nonatomic, assign) RCTBubblingEventBlock onClick;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTVirtualTextView.h>

@implementation RCTVirtualTextView

@end
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTVirtualTextViewManager.h>

#import <React/RCTVirtualTextShadowView.h>
#import <React/RCTVirtualTextView.h>
#import <React/RCTVirtualTextViewManager.h>

@implementation RCTVirtualTextViewManager

RCT_EXPORT_MODULE(RCTVirtualText)

- (UIView *)view
{
return [UIView new];
return [RCTVirtualTextView new];
}

- (RCTShadowView *)shadowView
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/React/Views/RCTView.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait;
/**
* (Experimental and unused for Paper) Pointer event handlers.
*/
@property (nonatomic, assign) RCTBubblingEventBlock onClick;
@property (nonatomic, assign) RCTBubblingEventBlock onPointerCancel;
@property (nonatomic, assign) RCTBubblingEventBlock onPointerDown;
@property (nonatomic, assign) RCTBubblingEventBlock onPointerMove;
Expand Down
1 change: 1 addition & 0 deletions packages/react-native/React/Views/RCTViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ - (RCTShadowView *)shadowView
RCT_CUSTOM_VIEW_PROPERTY(onTouchCancel, BOOL, RCTView) {}

// Experimental/WIP Pointer Events (not yet ready for use)
RCT_EXPORT_VIEW_PROPERTY(onClick, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPointerCancel, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPointerDown, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPointerMove, RCTBubblingEventBlock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ void TouchEventEmitter::onTouchCancel(TouchEvent const &event) const {
RawEvent::Category::ContinuousEnd);
}

void TouchEventEmitter::onClick(const PointerEvent &event) const {
dispatchPointerEvent(
"click",
event,
EventPriority::AsynchronousBatched,
RawEvent::Category::Discrete);
}

void TouchEventEmitter::onPointerCancel(const PointerEvent &event) const {
dispatchPointerEvent(
"pointerCancel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class TouchEventEmitter : public EventEmitter {
void onTouchEnd(TouchEvent const &event) const;
void onTouchCancel(TouchEvent const &event) const;

void onClick(PointerEvent const &event) const;
void onPointerCancel(PointerEvent const &event) const;
void onPointerDown(PointerEvent const &event) const;
void onPointerMove(PointerEvent const &event) const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ struct ViewEvents {
PointerOut = 27,
PointerOverCapture = 28,
PointerOutCapture = 29,

Click = 30,
ClickCapture = 31,
};

constexpr bool operator[](const Offset offset) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,18 @@ static inline ViewEvents convertRawProp(
"onPointerOut",
sourceValue[Offset::PointerOut],
defaultValue[Offset::PointerOut]);
result[Offset::Click] = convertRawProp(
context,
rawProps,
"onClick",
sourceValue[Offset::Click],
defaultValue[Offset::Click]);
result[Offset::ClickCapture] = convertRawProp(
context,
rawProps,
"onClickCapture",
sourceValue[Offset::ClickCapture],
defaultValue[Offset::ClickCapture]);

// PanResponder callbacks
result[Offset::MoveShouldSetResponder] = convertRawProp(
Expand Down

0 comments on commit 54a6922

Please sign in to comment.