Skip to content

Commit d6ca25b

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
Migrate UIManagerModuleConstants to Kotlin (facebook#50045)
Summary: Migrate com.facebook.react.uimanager.UIManagerModuleConstants to Kotlin. ## Changelog: [INTERNAL] - Migrate com.facebook.react.uimanager.UIManagerModuleConstants to Kotlin Pull Request resolved: facebook#50045 Test Plan: ```bash yarn test-android yarn android ``` Reviewed By: cortinico Differential Revision: D71307448 Pulled By: javache fbshipit-source-id: 63b8e54a0020d68d127c07f605a91a0dda403975
1 parent 00105b8 commit d6ca25b

File tree

4 files changed

+99
-126
lines changed

4 files changed

+99
-126
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public UIManagerModule(
127127
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(reactContext);
128128
mEventDispatcher = new EventDispatcherImpl(reactContext);
129129
mModuleConstants = createConstants(viewManagerResolver);
130-
mCustomDirectEvents = UIManagerModuleConstants.getDirectEventTypeConstants();
130+
mCustomDirectEvents = UIManagerModuleConstants.directEventTypeConstants;
131131
mViewManagerRegistry = new ViewManagerRegistry(viewManagerResolver);
132132
mUIImplementation =
133133
new UIImplementation(

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstants.java

Lines changed: 0 additions & 119 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and 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+
package com.facebook.react.uimanager
9+
10+
import android.view.accessibility.AccessibilityEvent
11+
import android.widget.ImageView
12+
import com.facebook.react.uimanager.events.TouchEventType
13+
import com.facebook.react.uimanager.events.TouchEventType.Companion.getJSEventName
14+
15+
/** Constants exposed to JS from [UIManagerModule]. */
16+
internal object UIManagerModuleConstants {
17+
const val ACTION_DISMISSED: String = "dismissed"
18+
const val ACTION_ITEM_SELECTED: String = "itemSelected"
19+
20+
@JvmField
21+
val bubblingEventTypeConstants: Map<String, Any> =
22+
mapOf(
23+
"topChange" to
24+
mapOf(
25+
"phasedRegistrationNames" to
26+
mapOf("bubbled" to "onChange", "captured" to "onChangeCapture")),
27+
"topSelect" to
28+
mapOf(
29+
"phasedRegistrationNames" to
30+
mapOf("bubbled" to "onSelect", "captured" to "onSelectCapture")),
31+
TouchEventType.getJSEventName(TouchEventType.START) to
32+
mapOf(
33+
"phasedRegistrationNames" to
34+
mapOf("bubbled" to "onTouchStart", "captured" to "onTouchStartCapture")),
35+
TouchEventType.getJSEventName(TouchEventType.MOVE) to
36+
mapOf(
37+
"phasedRegistrationNames" to
38+
mapOf("bubbled" to "onTouchMove", "captured" to "onTouchMoveCapture")),
39+
TouchEventType.getJSEventName(TouchEventType.END) to
40+
mapOf(
41+
"phasedRegistrationNames" to
42+
mapOf("bubbled" to "onTouchEnd", "captured" to "onTouchEndCapture")),
43+
TouchEventType.getJSEventName(TouchEventType.CANCEL) to
44+
mapOf(
45+
"phasedRegistrationNames" to
46+
mapOf("bubbled" to "onTouchCancel", "captured" to "onTouchCancelCapture")))
47+
48+
@JvmField
49+
val directEventTypeConstants: Map<String, Any> = run {
50+
val rn = "registrationName"
51+
mapOf(
52+
"topContentSizeChange" to mapOf(rn to "onContentSizeChange"),
53+
"topLayout" to mapOf(rn to "onLayout"),
54+
"topLoadingError" to mapOf(rn to "onLoadingError"),
55+
"topLoadingFinish" to mapOf(rn to "onLoadingFinish"),
56+
"topLoadingStart" to mapOf(rn to "onLoadingStart"),
57+
"topSelectionChange" to mapOf(rn to "onSelectionChange"),
58+
"topMessage" to mapOf(rn to "onMessage"),
59+
60+
// Scroll events are added as per task T22348735.
61+
// Subject for further improvement.
62+
"topScrollBeginDrag" to mapOf(rn to "onScrollBeginDrag"),
63+
"topScrollEndDrag" to mapOf(rn to "onScrollEndDrag"),
64+
"topScroll" to mapOf(rn to "onScroll"),
65+
"topMomentumScrollBegin" to mapOf(rn to "onMomentumScrollBegin"),
66+
"topMomentumScrollEnd" to mapOf(rn to "onMomentumScrollEnd"))
67+
}
68+
69+
@JvmField
70+
val constants: Map<String, Any> =
71+
mapOf(
72+
"UIView" to
73+
mapOf(
74+
"ContentMode" to
75+
mapOf(
76+
"ScaleAspectFit" to ImageView.ScaleType.FIT_CENTER.ordinal,
77+
"ScaleAspectFill" to ImageView.ScaleType.CENTER_CROP.ordinal,
78+
"ScaleAspectCenter" to ImageView.ScaleType.CENTER_INSIDE.ordinal)),
79+
"StyleConstants" to
80+
mapOf(
81+
"PointerEventsValues" to
82+
mapOf(
83+
"none" to PointerEvents.NONE.ordinal,
84+
"boxNone" to PointerEvents.BOX_NONE.ordinal,
85+
"boxOnly" to PointerEvents.BOX_ONLY.ordinal,
86+
"unspecified" to PointerEvents.AUTO.ordinal)),
87+
"AccessibilityEventTypes" to
88+
mapOf(
89+
"typeWindowStateChanged" to AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
90+
"typeViewFocused" to AccessibilityEvent.TYPE_VIEW_FOCUSED,
91+
"typeViewClicked" to AccessibilityEvent.TYPE_VIEW_CLICKED))
92+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ public class UIManagerModuleConstantsHelper {
3939
* registered on the JS side with the help of {@code UIManagerModule.getConstantsForViewManager}.
4040
*/
4141
/* package */ static Map<String, Object> createConstants(ViewManagerResolver resolver) {
42-
Map<String, Object> constants = UIManagerModuleConstants.getConstants();
42+
Map<String, Object> constants = UIManagerModuleConstants.constants;
4343
constants.put("ViewManagerNames", new ArrayList<>(resolver.getViewManagerNames()));
4444
constants.put("LazyViewManagersEnabled", true);
4545
return constants;
4646
}
4747

4848
public static Map<String, Object> getDefaultExportableEventTypes() {
4949
return MapBuilder.<String, Object>of(
50-
BUBBLING_EVENTS_KEY, UIManagerModuleConstants.getBubblingEventTypeConstants(),
51-
DIRECT_EVENTS_KEY, UIManagerModuleConstants.getDirectEventTypeConstants());
50+
BUBBLING_EVENTS_KEY, UIManagerModuleConstants.bubblingEventTypeConstants,
51+
DIRECT_EVENTS_KEY, UIManagerModuleConstants.directEventTypeConstants);
5252
}
5353

5454
private static void validateDirectEventNames(
@@ -90,13 +90,13 @@ private static void validateDirectEventNames(
9090
List<ViewManager> viewManagers,
9191
@Nullable Map<String, Object> allBubblingEventTypes,
9292
@Nullable Map<String, Object> allDirectEventTypes) {
93-
Map<String, Object> constants = UIManagerModuleConstants.getConstants();
93+
Map<String, Object> constants = UIManagerModuleConstants.constants;
9494

9595
// Generic/default event types:
9696
// All view managers are capable of dispatching these events.
9797
// They will be automatically registered with React Fiber.
98-
Map genericBubblingEventTypes = UIManagerModuleConstants.getBubblingEventTypeConstants();
99-
Map genericDirectEventTypes = UIManagerModuleConstants.getDirectEventTypeConstants();
98+
Map genericBubblingEventTypes = UIManagerModuleConstants.bubblingEventTypeConstants;
99+
Map genericDirectEventTypes = UIManagerModuleConstants.directEventTypeConstants;
100100

101101
// Cumulative event types:
102102
// View manager specific event types are collected as views are loaded.

0 commit comments

Comments
 (0)