mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-07 22:40:55 +08:00
Simplify OSS enums
Summary: Simplifying our OSS enums (remove private variables and methods) so that redex can more easily optimize them for us. Reviewed By: achen1, Feng23 Differential Revision: D9812796 fbshipit-source-id: 11a8272db41ff04399d1cdf366e28ddf1b07b7be
This commit is contained in:
committed by
Facebook Github Bot
parent
fa6035bda6
commit
c5186aeb46
@@ -29,30 +29,48 @@ public class AccessibilityDelegateUtil {
|
||||
*/
|
||||
|
||||
public enum AccessibilityRole {
|
||||
NONE(null),
|
||||
BUTTON("android.widget.Button"),
|
||||
LINK("android.widget.ViewGroup"),
|
||||
SEARCH("android.widget.EditText"),
|
||||
IMAGE("android.widget.ImageView"),
|
||||
IMAGEBUTTON("android.widget.ImageView"),
|
||||
KEYBOARDKEY("android.inputmethodservice.Keyboard$Key"),
|
||||
TEXT("android.widget.ViewGroup"),
|
||||
ADJUSTABLE("android.widget.SeekBar"),
|
||||
SUMMARY("android.widget.ViewGroup"),
|
||||
HEADER("android.widget.ViewGroup");
|
||||
NONE,
|
||||
BUTTON,
|
||||
LINK,
|
||||
SEARCH,
|
||||
IMAGE,
|
||||
IMAGEBUTTON,
|
||||
KEYBOARDKEY,
|
||||
TEXT,
|
||||
ADJUSTABLE,
|
||||
SUMMARY,
|
||||
HEADER;
|
||||
|
||||
@Nullable private final String mValue;
|
||||
|
||||
AccessibilityRole(String type) {
|
||||
mValue = type;
|
||||
public static String getValue(AccessibilityRole role) {
|
||||
switch (role) {
|
||||
case NONE:
|
||||
return null;
|
||||
case BUTTON:
|
||||
return "android.widget.Button";
|
||||
case LINK:
|
||||
return "android.widget.ViewGroup";
|
||||
case SEARCH:
|
||||
return "android.widget.EditText";
|
||||
case IMAGE:
|
||||
return "android.widget.ImageView";
|
||||
case IMAGEBUTTON:
|
||||
return "android.widget.ImageView";
|
||||
case KEYBOARDKEY:
|
||||
return "android.inputmethodservice.Keyboard$Key";
|
||||
case TEXT:
|
||||
return "android.widget.ViewGroup";
|
||||
case ADJUSTABLE:
|
||||
return "android.widget.SeekBar";
|
||||
case SUMMARY:
|
||||
return "android.widget.ViewGroup";
|
||||
case HEADER:
|
||||
return "android.widget.ViewGroup";
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid accessibility role value: " + role);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getValue() {
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public static AccessibilityRole fromValue(String value) {
|
||||
public static AccessibilityRole fromValue(@Nullable String value) {
|
||||
for (AccessibilityRole role : AccessibilityRole.values()) {
|
||||
if (role.name().equalsIgnoreCase(value)) {
|
||||
return role;
|
||||
@@ -105,7 +123,7 @@ public class AccessibilityDelegateUtil {
|
||||
if (role == null) {
|
||||
role = AccessibilityRole.NONE;
|
||||
}
|
||||
nodeInfo.setClassName(role.getValue());
|
||||
nodeInfo.setClassName(AccessibilityRole.getValue(role));
|
||||
if (Locale.getDefault().getLanguage().equals(new Locale("en").getLanguage())) {
|
||||
if (role.equals(AccessibilityRole.LINK)) {
|
||||
nodeInfo.setRoleDescription(context.getString(R.string.link_description));
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.Map;
|
||||
"phasedRegistrationNames",
|
||||
MapBuilder.of("bubbled", "onSelect", "captured", "onSelectCapture")))
|
||||
.put(
|
||||
TouchEventType.START.getJSEventName(),
|
||||
TouchEventType.getJSEventName(TouchEventType.START),
|
||||
MapBuilder.of(
|
||||
"phasedRegistrationNames",
|
||||
MapBuilder.of(
|
||||
@@ -44,7 +44,7 @@ import java.util.Map;
|
||||
"captured",
|
||||
"onTouchStartCapture")))
|
||||
.put(
|
||||
TouchEventType.MOVE.getJSEventName(),
|
||||
TouchEventType.getJSEventName(TouchEventType.MOVE),
|
||||
MapBuilder.of(
|
||||
"phasedRegistrationNames",
|
||||
MapBuilder.of(
|
||||
@@ -53,7 +53,7 @@ import java.util.Map;
|
||||
"captured",
|
||||
"onTouchMoveCapture")))
|
||||
.put(
|
||||
TouchEventType.END.getJSEventName(),
|
||||
TouchEventType.getJSEventName(TouchEventType.END),
|
||||
MapBuilder.of(
|
||||
"phasedRegistrationNames",
|
||||
MapBuilder.of(
|
||||
@@ -62,7 +62,7 @@ import java.util.Map;
|
||||
"captured",
|
||||
"onTouchEndCapture")))
|
||||
.put(
|
||||
TouchEventType.CANCEL.getJSEventName(),
|
||||
TouchEventType.getJSEventName(TouchEventType.CANCEL),
|
||||
MapBuilder.of(
|
||||
"phasedRegistrationNames",
|
||||
MapBuilder.of(
|
||||
|
||||
@@ -117,7 +117,7 @@ public class TouchEvent extends Event<TouchEvent> {
|
||||
|
||||
@Override
|
||||
public String getEventName() {
|
||||
return Assertions.assertNotNull(mTouchEventType).getJSEventName();
|
||||
return TouchEventType.getJSEventName(Assertions.assertNotNull(mTouchEventType));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,18 +11,23 @@ package com.facebook.react.uimanager.events;
|
||||
* Touch event types that JS module RCTEventEmitter can understand
|
||||
*/
|
||||
public enum TouchEventType {
|
||||
START("topTouchStart"),
|
||||
END("topTouchEnd"),
|
||||
MOVE("topTouchMove"),
|
||||
CANCEL("topTouchCancel");
|
||||
START,
|
||||
END,
|
||||
MOVE,
|
||||
CANCEL;
|
||||
|
||||
private final String mJSEventName;
|
||||
|
||||
TouchEventType(String jsEventName) {
|
||||
mJSEventName = jsEventName;
|
||||
}
|
||||
|
||||
public String getJSEventName() {
|
||||
return mJSEventName;
|
||||
public static String getJSEventName(TouchEventType type) {
|
||||
switch (type) {
|
||||
case START:
|
||||
return "topTouchStart";
|
||||
case END:
|
||||
return "topTouchEnd";
|
||||
case MOVE:
|
||||
return "topTouchMove";
|
||||
case CANCEL:
|
||||
return "topTouchCancel";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unexpected type " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class TouchesHelper {
|
||||
}
|
||||
|
||||
rctEventEmitter.receiveTouches(
|
||||
type.getJSEventName(),
|
||||
TouchEventType.getJSEventName(type),
|
||||
pointers,
|
||||
changedIndices);
|
||||
}
|
||||
|
||||
@@ -10,28 +10,23 @@ package com.facebook.react.uimanager.layoutanimation;
|
||||
* view creation.
|
||||
*/
|
||||
/* package */ enum AnimatedPropertyType {
|
||||
OPACITY("opacity"),
|
||||
SCALE_X("scaleX"),
|
||||
SCALE_Y("scaleY"),
|
||||
SCALE_XY("scaleXY");
|
||||
|
||||
private final String mName;
|
||||
|
||||
private AnimatedPropertyType(String name) {
|
||||
mName = name;
|
||||
}
|
||||
OPACITY,
|
||||
SCALE_X,
|
||||
SCALE_Y,
|
||||
SCALE_XY;
|
||||
|
||||
public static AnimatedPropertyType fromString(String name) {
|
||||
for (AnimatedPropertyType property : AnimatedPropertyType.values()) {
|
||||
if (property.toString().equalsIgnoreCase(name)) {
|
||||
return property;
|
||||
}
|
||||
switch (name) {
|
||||
case "opacity":
|
||||
return OPACITY;
|
||||
case "scaleX":
|
||||
return SCALE_X;
|
||||
case "scaleY":
|
||||
return SCALE_Y;
|
||||
case "scaleXY":
|
||||
return SCALE_XY;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported animated property: " + name);
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported animated property : " + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,29 +9,26 @@ package com.facebook.react.uimanager.layoutanimation;
|
||||
* Enum representing the different interpolators that can be used in layout animation configuration.
|
||||
*/
|
||||
/* package */ enum InterpolatorType {
|
||||
LINEAR("linear"),
|
||||
EASE_IN("easeIn"),
|
||||
EASE_OUT("easeOut"),
|
||||
EASE_IN_EASE_OUT("easeInEaseOut"),
|
||||
SPRING("spring");
|
||||
|
||||
private final String mName;
|
||||
|
||||
private InterpolatorType(String name) {
|
||||
mName = name;
|
||||
}
|
||||
LINEAR,
|
||||
EASE_IN,
|
||||
EASE_OUT,
|
||||
EASE_IN_EASE_OUT,
|
||||
SPRING;
|
||||
|
||||
public static InterpolatorType fromString(String name) {
|
||||
for (InterpolatorType type : InterpolatorType.values()) {
|
||||
if (type.toString().equalsIgnoreCase(name)) {
|
||||
return type;
|
||||
}
|
||||
switch (name.toLowerCase()) {
|
||||
case "linear":
|
||||
return LINEAR;
|
||||
case "easein":
|
||||
return EASE_IN;
|
||||
case "easeout":
|
||||
return EASE_OUT;
|
||||
case "easeineaseout":
|
||||
return EASE_IN_EASE_OUT;
|
||||
case "spring":
|
||||
return SPRING;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported interpolation type : " + name);
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported interpolation type : " + name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,19 +46,19 @@ public class LayoutAnimationController {
|
||||
|
||||
mShouldAnimateLayout = false;
|
||||
int globalDuration = config.hasKey("duration") ? config.getInt("duration") : 0;
|
||||
if (config.hasKey(LayoutAnimationType.CREATE.toString())) {
|
||||
if (config.hasKey(LayoutAnimationType.toString(LayoutAnimationType.CREATE))) {
|
||||
mLayoutCreateAnimation.initializeFromConfig(
|
||||
config.getMap(LayoutAnimationType.CREATE.toString()), globalDuration);
|
||||
config.getMap(LayoutAnimationType.toString(LayoutAnimationType.CREATE)), globalDuration);
|
||||
mShouldAnimateLayout = true;
|
||||
}
|
||||
if (config.hasKey(LayoutAnimationType.UPDATE.toString())) {
|
||||
if (config.hasKey(LayoutAnimationType.toString(LayoutAnimationType.UPDATE))) {
|
||||
mLayoutUpdateAnimation.initializeFromConfig(
|
||||
config.getMap(LayoutAnimationType.UPDATE.toString()), globalDuration);
|
||||
config.getMap(LayoutAnimationType.toString(LayoutAnimationType.UPDATE)), globalDuration);
|
||||
mShouldAnimateLayout = true;
|
||||
}
|
||||
if (config.hasKey(LayoutAnimationType.DELETE.toString())) {
|
||||
if (config.hasKey(LayoutAnimationType.toString(LayoutAnimationType.DELETE))) {
|
||||
mLayoutDeleteAnimation.initializeFromConfig(
|
||||
config.getMap(LayoutAnimationType.DELETE.toString()), globalDuration);
|
||||
config.getMap(LayoutAnimationType.toString(LayoutAnimationType.DELETE)), globalDuration);
|
||||
mShouldAnimateLayout = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,18 +9,20 @@ package com.facebook.react.uimanager.layoutanimation;
|
||||
* Enum representing the different animation type that can be specified in layout animation config.
|
||||
*/
|
||||
/* package */ enum LayoutAnimationType {
|
||||
CREATE("create"),
|
||||
UPDATE("update"),
|
||||
DELETE("delete");
|
||||
CREATE,
|
||||
UPDATE,
|
||||
DELETE;
|
||||
|
||||
private final String mName;
|
||||
|
||||
private LayoutAnimationType(String name) {
|
||||
mName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mName;
|
||||
public static String toString(LayoutAnimationType type) {
|
||||
switch (type) {
|
||||
case CREATE:
|
||||
return "create";
|
||||
case UPDATE:
|
||||
return "update";
|
||||
case DELETE:
|
||||
return "delete";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported LayoutAnimationType: " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,11 +271,11 @@ public class ReactScrollViewManager
|
||||
|
||||
public static Map<String, Object> createExportedCustomDirectEventTypeConstants() {
|
||||
return MapBuilder.<String, Object>builder()
|
||||
.put(ScrollEventType.SCROLL.getJSEventName(), MapBuilder.of("registrationName", "onScroll"))
|
||||
.put(ScrollEventType.BEGIN_DRAG.getJSEventName(), MapBuilder.of("registrationName", "onScrollBeginDrag"))
|
||||
.put(ScrollEventType.END_DRAG.getJSEventName(), MapBuilder.of("registrationName", "onScrollEndDrag"))
|
||||
.put(ScrollEventType.MOMENTUM_BEGIN.getJSEventName(), MapBuilder.of("registrationName", "onMomentumScrollBegin"))
|
||||
.put(ScrollEventType.MOMENTUM_END.getJSEventName(), MapBuilder.of("registrationName", "onMomentumScrollEnd"))
|
||||
.put(ScrollEventType.getJSEventName(ScrollEventType.SCROLL), MapBuilder.of("registrationName", "onScroll"))
|
||||
.put(ScrollEventType.getJSEventName(ScrollEventType.BEGIN_DRAG), MapBuilder.of("registrationName", "onScrollBeginDrag"))
|
||||
.put(ScrollEventType.getJSEventName(ScrollEventType.END_DRAG), MapBuilder.of("registrationName", "onScrollEndDrag"))
|
||||
.put(ScrollEventType.getJSEventName(ScrollEventType.MOMENTUM_BEGIN), MapBuilder.of("registrationName", "onMomentumScrollBegin"))
|
||||
.put(ScrollEventType.getJSEventName(ScrollEventType.MOMENTUM_END), MapBuilder.of("registrationName", "onMomentumScrollEnd"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class ScrollEvent extends Event<ScrollEvent> {
|
||||
|
||||
@Override
|
||||
public String getEventName() {
|
||||
return Assertions.assertNotNull(mScrollEventType).getJSEventName();
|
||||
return ScrollEventType.getJSEventName(Assertions.assertNotNull(mScrollEventType));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,19 +11,26 @@ package com.facebook.react.views.scroll;
|
||||
* Scroll event types that JS module RCTEventEmitter can understand
|
||||
*/
|
||||
public enum ScrollEventType {
|
||||
BEGIN_DRAG("topScrollBeginDrag"),
|
||||
END_DRAG("topScrollEndDrag"),
|
||||
SCROLL("topScroll"),
|
||||
MOMENTUM_BEGIN("topMomentumScrollBegin"),
|
||||
MOMENTUM_END("topMomentumScrollEnd");
|
||||
BEGIN_DRAG,
|
||||
END_DRAG,
|
||||
SCROLL,
|
||||
MOMENTUM_BEGIN,
|
||||
MOMENTUM_END;
|
||||
|
||||
private final String mJSEventName;
|
||||
|
||||
ScrollEventType(String jsEventName) {
|
||||
mJSEventName = jsEventName;
|
||||
}
|
||||
|
||||
public String getJSEventName() {
|
||||
return mJSEventName;
|
||||
public static String getJSEventName(ScrollEventType type) {
|
||||
switch (type) {
|
||||
case BEGIN_DRAG:
|
||||
return "topScrollBeginDrag";
|
||||
case END_DRAG:
|
||||
return "topScrollEndDrag";
|
||||
case SCROLL:
|
||||
return "topScroll";
|
||||
case MOMENTUM_BEGIN:
|
||||
return "topMomentumScrollBegin";
|
||||
case MOMENTUM_END:
|
||||
return "topMomentumScrollEnd";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported ScrollEventType: " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
@Override
|
||||
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
|
||||
return MapBuilder.<String, Object>builder()
|
||||
.put(ScrollEventType.SCROLL.getJSEventName(), MapBuilder.of("registrationName", "onScroll"))
|
||||
.put(ScrollEventType.getJSEventName(ScrollEventType.SCROLL), MapBuilder.of("registrationName", "onScroll"))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,13 +53,13 @@ public class ReactViewBackgroundDrawable extends Drawable {
|
||||
// 0 == 0x00000000, all bits set to 0.
|
||||
private static final int ALL_BITS_UNSET = 0;
|
||||
|
||||
private static enum BorderStyle {
|
||||
private enum BorderStyle {
|
||||
SOLID,
|
||||
DASHED,
|
||||
DOTTED;
|
||||
|
||||
public @Nullable PathEffect getPathEffect(float borderWidth) {
|
||||
switch (this) {
|
||||
public static @Nullable PathEffect getPathEffect(BorderStyle style, float borderWidth) {
|
||||
switch (style) {
|
||||
case SOLID:
|
||||
return null;
|
||||
|
||||
@@ -957,7 +957,7 @@ public class ReactViewBackgroundDrawable extends Drawable {
|
||||
*/
|
||||
private void updatePathEffect() {
|
||||
mPathEffectForBorderStyle = mBorderStyle != null
|
||||
? mBorderStyle.getPathEffect(getFullBorderWidth())
|
||||
? BorderStyle.getPathEffect(mBorderStyle, getFullBorderWidth())
|
||||
: null;
|
||||
|
||||
mPaint.setPathEffect(mPathEffectForBorderStyle);
|
||||
|
||||
Reference in New Issue
Block a user