Skip to content

Commit d2fc19f

Browse files
dulmandakhfacebook-github-bot
authored andcommitted
fix lint error/warnings (#23333)
Summary: Fix lint errors and warning, which might be a cause of various crashes on older Android OS, using Android Support Library. ```bash ./gradlew :ReactAndroid:lint ``` [Android] [Changed] - fix lint error/warnings Pull Request resolved: #23333 Differential Revision: D14019322 Pulled By: mdvacca fbshipit-source-id: 74c98da269c318cf3b114c8d9c876186369f2b8c
1 parent 8ccc55f commit d2fc19f

File tree

11 files changed

+29
-12
lines changed

11 files changed

+29
-12
lines changed

ReactAndroid/src/main/java/com/facebook/react/HeadlessJsTaskService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Set;
1313
import java.util.concurrent.CopyOnWriteArraySet;
1414

15+
import android.annotation.SuppressLint;
1516
import android.app.Service;
1617
import android.content.BroadcastReceiver;
1718
import android.content.Context;
@@ -67,6 +68,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
6768
/**
6869
* Acquire a wake lock to ensure the device doesn't go to sleep while processing background tasks.
6970
*/
71+
@SuppressLint("WakelockTimeout")
7072
public static void acquireWakeLockNow(Context context) {
7173
if (sWakeLock == null || !sWakeLock.isHeld()) {
7274
PowerManager powerManager =

ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoModule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package com.facebook.react.modules.systeminfo;
99

10+
import android.annotation.SuppressLint;
1011
import android.app.UiModeManager;
1112
import android.content.res.Configuration;
1213
import android.os.Build;
@@ -29,6 +30,7 @@
2930
* Module that exposes Android Constants to JS.
3031
*/
3132
@ReactModule(name = AndroidInfoModule.NAME)
33+
@SuppressLint("HardwareIds")
3234
public class AndroidInfoModule extends ReactContextBaseJavaModule {
3335
public static final String NAME = "PlatformConstants";
3436
private static final String IS_TESTING = "IS_TESTING";

ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import android.graphics.Color;
99
import android.os.Build;
10+
import android.support.v4.view.ViewCompat;
1011
import android.view.View;
1112
import android.view.ViewParent;
1213
import com.facebook.react.R;
@@ -156,13 +157,13 @@ public void setViewStates(T view, ReadableArray accessibilityStates) {
156157
@ReactProp(name = PROP_IMPORTANT_FOR_ACCESSIBILITY)
157158
public void setImportantForAccessibility(T view, String importantForAccessibility) {
158159
if (importantForAccessibility == null || importantForAccessibility.equals("auto")) {
159-
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
160+
ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
160161
} else if (importantForAccessibility.equals("yes")) {
161-
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
162+
ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
162163
} else if (importantForAccessibility.equals("no")) {
163-
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
164+
ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO);
164165
} else if (importantForAccessibility.equals("no-hide-descendants")) {
165-
view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
166+
ViewCompat.setImportantForAccessibility(view, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
166167
}
167168
}
168169

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollContainerView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package com.facebook.react.views.scroll;
77

88
import android.content.Context;
9+
import android.support.v4.view.ViewCompat;
910
import android.view.ViewGroup;
1011
import android.widget.HorizontalScrollView;
1112
import com.facebook.react.modules.i18nmanager.I18nUtil;
@@ -19,7 +20,7 @@ public class ReactHorizontalScrollContainerView extends ViewGroup {
1920
public ReactHorizontalScrollContainerView(Context context) {
2021
super(context);
2122
mLayoutDirection =
22-
I18nUtil.getInstance().isRTL(context) ? LAYOUT_DIRECTION_RTL : LAYOUT_DIRECTION_LTR;
23+
I18nUtil.getInstance().isRTL(context) ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR;
2324
mCurrentWidth = 0;
2425
}
2526

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public void fling(int velocityX) {
305305
// as there is content. See #onOverScrolled() to see the second part of this change which properly
306306
// aborts the scroller animation when we get to the bottom of the ScrollView content.
307307

308-
int scrollWindowWidth = getWidth() - getPaddingStart() - getPaddingEnd();
308+
int scrollWindowWidth = getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);
309309

310310
mScroller.fling(
311311
getScrollX(), // startX
@@ -501,7 +501,7 @@ private int predictFinalScrollPosition(int velocityX) {
501501

502502
// predict where a fling would end up so we can scroll to the nearest snap offset
503503
int maximumOffset = Math.max(0, computeHorizontalScrollRange() - getWidth());
504-
int width = getWidth() - getPaddingStart() - getPaddingEnd();
504+
int width = getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);
505505
scroller.fling(
506506
getScrollX(), // startX
507507
getScrollY(), // startY
@@ -583,7 +583,7 @@ private void flingAndSnap(int velocityX) {
583583
int largerOffset = maximumOffset;
584584
int firstOffset = 0;
585585
int lastOffset = maximumOffset;
586-
int width = getWidth() - getPaddingStart() - getPaddingEnd();
586+
int width = getWidth() - ViewCompat.getPaddingStart(this) - ViewCompat.getPaddingEnd(this);
587587

588588
// offsets are from the right edge in RTL layouts
589589
boolean isRTL = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == ViewCompat.LAYOUT_DIRECTION_RTL;

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactBaseTextShadowNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package com.facebook.react.views.text;
88

9+
import android.annotation.TargetApi;
910
import android.graphics.Color;
1011
import android.graphics.Typeface;
1112
import android.os.Build;
@@ -37,6 +38,7 @@
3738
* <p>This also node calculates {@link Spannable} object based on subnodes of the same type, which
3839
* can be used in concrete classes to feed native views and compute layout.
3940
*/
41+
@TargetApi(Build.VERSION_CODES.M)
4042
public abstract class ReactBaseTextShadowNode extends LayoutShadowNode {
4143

4244
private static final String INLINE_IMAGE_PLACEHOLDER = "I";

ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package com.facebook.react.views.text;
88

9+
import android.annotation.TargetApi;
910
import android.os.Build;
1011
import android.text.BoringLayout;
1112
import android.text.Layout;
@@ -37,6 +38,7 @@
3738
* <p>The class measures text in {@code <Text>} view and feeds native {@link TextView} using {@code
3839
* Spannable} object constructed in superclass.
3940
*/
41+
@TargetApi(Build.VERSION_CODES.M)
4042
public class ReactTextShadowNode extends ReactBaseTextShadowNode {
4143

4244
// It's important to pass the ANTI_ALIAS_FLAG flag to the constructor rather than setting it

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputShadowNode.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
package com.facebook.react.views.textinput;
99

10+
import android.annotation.TargetApi;
1011
import android.os.Build;
12+
import android.support.v4.view.ViewCompat;
1113
import android.text.Layout;
1214
import android.util.TypedValue;
1315
import android.view.ViewGroup;
@@ -33,6 +35,7 @@
3335
import javax.annotation.Nullable;
3436

3537
@VisibleForTesting
38+
@TargetApi(Build.VERSION_CODES.M)
3639
public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
3740
implements YogaMeasureFunction {
3841

@@ -49,7 +52,7 @@ public class ReactTextInputShadowNode extends ReactBaseTextShadowNode
4952

5053
public ReactTextInputShadowNode() {
5154
mTextBreakStrategy = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) ?
52-
0 : Layout.BREAK_STRATEGY_SIMPLE;
55+
Layout.BREAK_STRATEGY_SIMPLE : Layout.BREAK_STRATEGY_HIGH_QUALITY;
5356

5457
initMeasureFunction();
5558
}
@@ -71,9 +74,9 @@ public void setThemedContext(ThemedReactContext themedContext) {
7174
// So, we have to enforce it as a default padding.
7275
// TODO #7120264: Cache this stuff better.
7376
EditText editText = new EditText(getThemedContext());
74-
setDefaultPadding(Spacing.START, editText.getPaddingStart());
77+
setDefaultPadding(Spacing.START, ViewCompat.getPaddingStart(editText));
7578
setDefaultPadding(Spacing.TOP, editText.getPaddingTop());
76-
setDefaultPadding(Spacing.END, editText.getPaddingEnd());
79+
setDefaultPadding(Spacing.END, ViewCompat.getPaddingEnd(editText));
7780
setDefaultPadding(Spacing.BOTTOM, editText.getPaddingBottom());
7881

7982
mDummyEditText = editText;

ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbarManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.content.res.Resources;
1212
import android.content.res.TypedArray;
1313
import android.graphics.Color;
14+
import android.support.v4.view.ViewCompat;
1415
import android.util.LayoutDirection;
1516
import android.view.MenuItem;
1617
import android.view.View;
@@ -62,7 +63,7 @@ public void setOverflowIcon(ReactToolbar view, @Nullable ReadableMap overflowIco
6263

6364
@ReactProp(name = "rtl")
6465
public void setRtl(ReactToolbar view, boolean rtl) {
65-
view.setLayoutDirection(rtl ? LayoutDirection.RTL : LayoutDirection.LTR);
66+
ViewCompat.setLayoutDirection(view, rtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
6667
}
6768

6869
@ReactProp(name = "subtitle")

ReactAndroid/src/main/java/com/facebook/react/views/view/ReactDrawableHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package com.facebook.react.views.view;
99

10+
import android.annotation.TargetApi;
1011
import android.content.Context;
1112
import android.content.res.ColorStateList;
1213
import android.graphics.Color;
@@ -29,6 +30,7 @@ public class ReactDrawableHelper {
2930

3031
private static final TypedValue sResolveOutValue = new TypedValue();
3132

33+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
3234
public static Drawable createDrawableFromJSDescription(
3335
Context context,
3436
ReadableMap drawableDescriptionDict) {

0 commit comments

Comments
 (0)