From c3b47e55238b7f40e2a1cdff3dc41b40ec380dab Mon Sep 17 00:00:00 2001 From: "Andrew Y. Chen" Date: Mon, 21 Aug 2017 15:07:54 -0700 Subject: [PATCH] Remove appcompat dep from react/views/toolbar Reviewed By: AaaChiuuu Differential Revision: D5651764 fbshipit-source-id: c8cf730bf2086d205a43a535f3f12ae2af0caa5f --- .../com/facebook/react/views/toolbar/BUCK | 1 - .../views/toolbar/ReactToolbarManager.java | 49 ++++++++++++------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/BUCK index b069baf486e..bcc3f9cc769 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/BUCK @@ -12,7 +12,6 @@ android_library( ], deps = [ YOGA_TARGET, - react_native_dep("android_res/com/facebook/catalyst/appcompat:appcompat"), react_native_dep("libraries/fresco/fresco-react-native:fbcore"), react_native_dep("libraries/fresco/fresco-react-native:fresco-drawee"), react_native_dep("libraries/fresco/fresco-react-native:fresco-react-native"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbarManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbarManager.java index b37040a22f3..6521544d533 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbarManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbarManager.java @@ -9,10 +9,6 @@ package com.facebook.react.views.toolbar; -import javax.annotation.Nullable; - -import java.util.Map; - import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; @@ -20,8 +16,6 @@ import android.graphics.Color; import android.util.LayoutDirection; import android.view.MenuItem; import android.view.View; - -import com.facebook.react.R; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.common.MapBuilder; @@ -32,6 +26,8 @@ import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.views.toolbar.events.ToolbarClickEvent; +import java.util.Map; +import javax.annotation.Nullable; /** * Manages instances of ReactToolbar. @@ -169,15 +165,17 @@ public class ReactToolbarManager extends ViewGroupManager { TypedArray contentInsets = null; try { - toolbarStyle = theme - .obtainStyledAttributes(new int[]{R.attr.toolbarStyle}); + toolbarStyle = + theme.obtainStyledAttributes(new int[] {getIdentifier(context, "toolbarStyle")}); int toolbarStyleResId = toolbarStyle.getResourceId(0, 0); - contentInsets = theme.obtainStyledAttributes( - toolbarStyleResId, new int[]{ - R.attr.contentInsetStart, - R.attr.contentInsetEnd, + contentInsets = + theme.obtainStyledAttributes( + toolbarStyleResId, + new int[] { + getIdentifier(context, "contentInsetStart"), + getIdentifier(context, "contentInsetEnd"), }); int contentInsetStart = contentInsets.getDimensionPixelSize(0, 0); @@ -199,14 +197,18 @@ public class ReactToolbarManager extends ViewGroupManager { TypedArray subtitleTextAppearance = null; try { - toolbarStyle = theme - .obtainStyledAttributes(new int[]{R.attr.toolbarStyle}); + toolbarStyle = + theme.obtainStyledAttributes(new int[] {getIdentifier(context, "toolbarStyle")}); + int toolbarStyleResId = toolbarStyle.getResourceId(0, 0); - textAppearances = theme.obtainStyledAttributes( - toolbarStyleResId, new int[]{ - R.attr.titleTextAppearance, - R.attr.subtitleTextAppearance, - }); + textAppearances = + theme.obtainStyledAttributes( + toolbarStyleResId, + new int[] { + getIdentifier(context, "titleTextAppearance"), + getIdentifier(context, "subtitleTextAppearance"), + }); + int titleTextAppearanceResId = textAppearances.getResourceId(0, 0); int subtitleTextAppearanceResId = textAppearances.getResourceId(1, 0); @@ -233,4 +235,13 @@ public class ReactToolbarManager extends ViewGroupManager { } } + /** + * The appcompat-v7 BUCK dep is listed as a provided_dep, which complains that + * com.facebook.react.R doesn't exist. Since the attributes provided from a parent, we can access + * those attributes dynamically. + */ + private static int getIdentifier(Context context, String name) { + return context.getResources().getIdentifier(name, "attr", context.getPackageName()); + } + }