29
29
import com .facebook .react .uimanager .annotations .ReactProp ;
30
30
import com .facebook .react .uimanager .annotations .ReactPropGroup ;
31
31
import com .facebook .react .uimanager .events .EventDispatcher ;
32
+ import com .facebook .react .views .common .ReactViewBlurEvent ;
33
+ import com .facebook .react .views .common .ReactViewFocusEvent ;
32
34
import com .facebook .yoga .YogaConstants ;
33
35
import java .util .Locale ;
34
36
import java .util .Map ;
@@ -234,8 +236,7 @@ public void setFocusable(final ReactViewGroup view, boolean focusable) {
234
236
@ Override
235
237
public void onClick (View v ) {
236
238
final EventDispatcher mEventDispatcher =
237
- UIManagerHelper .getEventDispatcherForReactTag (
238
- (ReactContext ) view .getContext (), view .getId ());
239
+ getEventDispatcher ((ReactContext ) view .getContext (), view );
239
240
if (mEventDispatcher == null ) {
240
241
return ;
241
242
}
@@ -254,6 +255,27 @@ public void onClick(View v) {
254
255
}
255
256
}
256
257
258
+ private static EventDispatcher getEventDispatcher (
259
+ ReactContext reactContext , ReactViewGroup view ) {
260
+ return UIManagerHelper .getEventDispatcherForReactTag (reactContext , view .getId ());
261
+ }
262
+
263
+ @ Override
264
+ protected void addEventEmitters (
265
+ final ThemedReactContext reactContext , final ReactViewGroup view ) {
266
+ view .setOnFocusChangeListener (
267
+ new View .OnFocusChangeListener () {
268
+ public void onFocusChange (View v , boolean hasFocus ) {
269
+ EventDispatcher eventDispatcher = getEventDispatcher (reactContext , view );
270
+ if (hasFocus ) {
271
+ eventDispatcher .dispatchEvent (new ReactViewFocusEvent (view .getId ()));
272
+ } else {
273
+ eventDispatcher .dispatchEvent (new ReactViewBlurEvent (view .getId ()));
274
+ }
275
+ }
276
+ });
277
+ }
278
+
257
279
@ ReactProp (name = ViewProps .OVERFLOW )
258
280
public void setOverflow (ReactViewGroup view , String overflow ) {
259
281
view .setOverflow (overflow );
0 commit comments