UNPKG

3.27 kBtext/x-cView Raw
1/*
2 * Copyright (c) Facebook, Inc. and its affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#import <UIKit/UIKit.h>
9
10#import <React/RCTBridge.h>
11
12typedef NS_ENUM(NSInteger, RCTTextEventType)
13{
14 RCTTextEventTypeFocus,
15 RCTTextEventTypeBlur,
16 RCTTextEventTypeChange,
17 RCTTextEventTypeSubmit,
18 RCTTextEventTypeEnd,
19 RCTTextEventTypeKeyPress
20};
21
22/**
23 * The threshold at which text inputs will start warning that the JS thread
24 * has fallen behind (resulting in poor input performance, missed keys, etc.)
25 */
26RCT_EXTERN const NSInteger RCTTextUpdateLagWarningThreshold;
27
28/**
29 * Takes an input event name and normalizes it to the form that is required
30 * by the events system (currently that means starting with the "top" prefix,
31 * but that's an implementation detail that may change in future).
32 */
33RCT_EXTERN NSString *RCTNormalizeInputEventName(NSString *eventName);
34
35@protocol RCTEvent <NSObject>
36@required
37
38@property (nonatomic, strong, readonly) NSNumber *viewTag;
39@property (nonatomic, copy, readonly) NSString *eventName;
40
41- (BOOL)canCoalesce;
42
43/** used directly for doing a JS call */
44+ (NSString *)moduleDotMethod;
45
46/** must contain only JSON compatible values */
47- (NSArray *)arguments;
48
49@optional
50
51/**
52 * Coalescing related methods must only be implemented if canCoalesce
53 * returns YES.
54 */
55@property (nonatomic, assign, readonly) uint16_t coalescingKey;
56- (id<RCTEvent>)coalesceWithEvent:(id<RCTEvent>)newEvent;
57
58@end
59
60/**
61 * This protocol allows observing events dispatched by RCTEventDispatcher.
62 */
63@protocol RCTEventDispatcherObserver <NSObject>
64
65/**
66 * Called before dispatching an event, on the same thread the event was
67 * dispatched from.
68 */
69- (void)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event;
70
71@end
72
73
74/**
75 * This class wraps the -[RCTBridge enqueueJSCall:args:] method, and
76 * provides some convenience methods for generating event calls.
77 */
78@interface RCTEventDispatcher : NSObject <RCTBridgeModule>
79
80/**
81 * Deprecated, do not use.
82 */
83- (void)sendAppEventWithName:(NSString *)name body:(id)body
84__deprecated_msg("Subclass RCTEventEmitter instead");
85
86/**
87 * Deprecated, do not use.
88 */
89- (void)sendDeviceEventWithName:(NSString *)name body:(id)body
90__deprecated_msg("Subclass RCTEventEmitter instead");
91
92/**
93 * Send a text input/focus event. For internal use only.
94 */
95- (void)sendTextEventWithType:(RCTTextEventType)type
96 reactTag:(NSNumber *)reactTag
97 text:(NSString *)text
98 key:(NSString *)key
99 eventCount:(NSInteger)eventCount;
100
101/**
102 * Send a pre-prepared event object.
103 *
104 * Events are sent to JS as soon as the thread is free to process them.
105 * If an event can be coalesced and there is another compatible event waiting, the coalescing will happen immediately.
106 */
107- (void)sendEvent:(id<RCTEvent>)event;
108
109/**
110 * Add an event dispatcher observer.
111 */
112- (void)addDispatchObserver:(id<RCTEventDispatcherObserver>)observer;
113
114/**
115 * Remove an event dispatcher observer.
116 */
117- (void)removeDispatchObserver:(id<RCTEventDispatcherObserver>)observer;
118
119@end
120
121@interface RCTBridge (RCTEventDispatcher)
122
123- (RCTEventDispatcher *)eventDispatcher;
124
125@end