forked from react/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseViewManagerDelegate.java
More file actions
129 lines (123 loc) · 5.22 KB
/
Copy pathBaseViewManagerDelegate.java
File metadata and controls
129 lines (123 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.uimanager;
import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ColorPropConverter;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.yoga.YogaConstants;
/**
* This is a base implementation of {@link ViewManagerDelegate} which supports setting properties
* that every view should support, such as rotation, background color, etc.
*/
public abstract class BaseViewManagerDelegate<T extends View, U extends BaseViewManagerInterface<T>>
implements ViewManagerDelegate<T> {
protected final U mViewManager;
public BaseViewManagerDelegate(U viewManager) {
mViewManager = viewManager;
}
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case ViewProps.ACCESSIBILITY_ACTIONS:
mViewManager.setAccessibilityActions(view, (ReadableArray) value);
break;
case ViewProps.ACCESSIBILITY_HINT:
mViewManager.setAccessibilityHint(view, (String) value);
break;
case ViewProps.ACCESSIBILITY_LABEL:
mViewManager.setAccessibilityLabel(view, (String) value);
break;
case ViewProps.ACCESSIBILITY_LIVE_REGION:
mViewManager.setAccessibilityLiveRegion(view, (String) value);
break;
case ViewProps.ACCESSIBILITY_ROLE:
mViewManager.setAccessibilityRole(view, (String) value);
break;
case ViewProps.ACCESSIBILITY_STATE:
mViewManager.setViewState(view, (ReadableMap) value);
break;
case ViewProps.ACCESSIBILITY_COLLECTION_INFO:
mViewManager.setAccessibilityCollectionInfo(view, (ReadableMap) value);
break;
case ViewProps.ACCESSIBILITY_COLLECTION_ITEM_INFO:
mViewManager.setAccessibilityCollectionItemInfo(view, (ReadableMap) value);
break;
case ViewProps.BACKGROUND_COLOR:
mViewManager.setBackgroundColor(
view, value == null ? 0 : ColorPropConverter.getColor(value, view.getContext()));
break;
case ViewProps.BORDER_RADIUS:
mViewManager.setBorderRadius(
view, value == null ? YogaConstants.UNDEFINED : ((Double) value).floatValue());
break;
case ViewProps.BORDER_BOTTOM_LEFT_RADIUS:
mViewManager.setBorderBottomLeftRadius(
view, value == null ? YogaConstants.UNDEFINED : ((Double) value).floatValue());
break;
case ViewProps.BORDER_BOTTOM_RIGHT_RADIUS:
mViewManager.setBorderBottomRightRadius(
view, value == null ? YogaConstants.UNDEFINED : ((Double) value).floatValue());
break;
case ViewProps.BORDER_TOP_LEFT_RADIUS:
mViewManager.setBorderTopLeftRadius(
view, value == null ? YogaConstants.UNDEFINED : ((Double) value).floatValue());
break;
case ViewProps.BORDER_TOP_RIGHT_RADIUS:
mViewManager.setBorderTopRightRadius(
view, value == null ? YogaConstants.UNDEFINED : ((Double) value).floatValue());
break;
case ViewProps.ELEVATION:
mViewManager.setElevation(view, value == null ? 0.0f : ((Double) value).floatValue());
break;
case ViewProps.SHADOW_COLOR:
mViewManager.setShadowColor(
view, value == null ? 0 : ColorPropConverter.getColor(value, view.getContext()));
break;
case ViewProps.IMPORTANT_FOR_ACCESSIBILITY:
mViewManager.setImportantForAccessibility(view, (String) value);
break;
case ViewProps.NATIVE_ID:
mViewManager.setNativeId(view, (String) value);
break;
case ViewProps.OPACITY:
mViewManager.setOpacity(view, value == null ? 1.0f : ((Double) value).floatValue());
break;
case ViewProps.RENDER_TO_HARDWARE_TEXTURE:
//noinspection SimplifiableConditionalExpression
mViewManager.setRenderToHardwareTexture(view, value == null ? false : (boolean) value);
break;
case ViewProps.ROTATION:
mViewManager.setRotation(view, value == null ? 0.0f : ((Double) value).floatValue());
break;
case ViewProps.SCALE_X:
mViewManager.setScaleX(view, value == null ? 1.0f : ((Double) value).floatValue());
break;
case ViewProps.SCALE_Y:
mViewManager.setScaleY(view, value == null ? 1.0f : ((Double) value).floatValue());
break;
case ViewProps.TEST_ID:
mViewManager.setTestId(view, (String) value);
break;
case ViewProps.TRANSFORM:
mViewManager.setTransform(view, (ReadableArray) value);
break;
case ViewProps.TRANSLATE_X:
mViewManager.setTranslateX(view, value == null ? 0.0f : ((Double) value).floatValue());
break;
case ViewProps.TRANSLATE_Y:
mViewManager.setTranslateY(view, value == null ? 0.0f : ((Double) value).floatValue());
break;
case ViewProps.Z_INDEX:
mViewManager.setZIndex(view, value == null ? 0.0f : ((Double) value).floatValue());
break;
}
}
@Override
public void receiveCommand(T view, String commandName, ReadableArray args) {}
}