Remove appcompat dep from react/views/toolbar

Reviewed By: AaaChiuuu

Differential Revision: D5651764

fbshipit-source-id: c8cf730bf2086d205a43a535f3f12ae2af0caa5f
This commit is contained in:
Andrew Y. Chen 2017-08-21 15:07:54 -07:00 committed by Facebook Github Bot
parent 73f17908e6
commit c3b47e5523
2 changed files with 30 additions and 20 deletions

View File

@ -12,7 +12,6 @@ android_library(
], ],
deps = [ deps = [
YOGA_TARGET, 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:fbcore"),
react_native_dep("libraries/fresco/fresco-react-native:fresco-drawee"), react_native_dep("libraries/fresco/fresco-react-native:fresco-drawee"),
react_native_dep("libraries/fresco/fresco-react-native:fresco-react-native"), react_native_dep("libraries/fresco/fresco-react-native:fresco-react-native"),

View File

@ -9,10 +9,6 @@
package com.facebook.react.views.toolbar; package com.facebook.react.views.toolbar;
import javax.annotation.Nullable;
import java.util.Map;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
@ -20,8 +16,6 @@ import android.graphics.Color;
import android.util.LayoutDirection; import android.util.LayoutDirection;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.facebook.react.R;
import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder; 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.annotations.ReactProp;
import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.views.toolbar.events.ToolbarClickEvent; import com.facebook.react.views.toolbar.events.ToolbarClickEvent;
import java.util.Map;
import javax.annotation.Nullable;
/** /**
* Manages instances of ReactToolbar. * Manages instances of ReactToolbar.
@ -169,15 +165,17 @@ public class ReactToolbarManager extends ViewGroupManager<ReactToolbar> {
TypedArray contentInsets = null; TypedArray contentInsets = null;
try { try {
toolbarStyle = theme toolbarStyle =
.obtainStyledAttributes(new int[]{R.attr.toolbarStyle}); theme.obtainStyledAttributes(new int[] {getIdentifier(context, "toolbarStyle")});
int toolbarStyleResId = toolbarStyle.getResourceId(0, 0); int toolbarStyleResId = toolbarStyle.getResourceId(0, 0);
contentInsets = theme.obtainStyledAttributes( contentInsets =
toolbarStyleResId, new int[]{ theme.obtainStyledAttributes(
R.attr.contentInsetStart, toolbarStyleResId,
R.attr.contentInsetEnd, new int[] {
getIdentifier(context, "contentInsetStart"),
getIdentifier(context, "contentInsetEnd"),
}); });
int contentInsetStart = contentInsets.getDimensionPixelSize(0, 0); int contentInsetStart = contentInsets.getDimensionPixelSize(0, 0);
@ -199,14 +197,18 @@ public class ReactToolbarManager extends ViewGroupManager<ReactToolbar> {
TypedArray subtitleTextAppearance = null; TypedArray subtitleTextAppearance = null;
try { try {
toolbarStyle = theme toolbarStyle =
.obtainStyledAttributes(new int[]{R.attr.toolbarStyle}); theme.obtainStyledAttributes(new int[] {getIdentifier(context, "toolbarStyle")});
int toolbarStyleResId = toolbarStyle.getResourceId(0, 0); int toolbarStyleResId = toolbarStyle.getResourceId(0, 0);
textAppearances = theme.obtainStyledAttributes( textAppearances =
toolbarStyleResId, new int[]{ theme.obtainStyledAttributes(
R.attr.titleTextAppearance, toolbarStyleResId,
R.attr.subtitleTextAppearance, new int[] {
getIdentifier(context, "titleTextAppearance"),
getIdentifier(context, "subtitleTextAppearance"),
}); });
int titleTextAppearanceResId = textAppearances.getResourceId(0, 0); int titleTextAppearanceResId = textAppearances.getResourceId(0, 0);
int subtitleTextAppearanceResId = textAppearances.getResourceId(1, 0); int subtitleTextAppearanceResId = textAppearances.getResourceId(1, 0);
@ -233,4 +235,13 @@ public class ReactToolbarManager extends ViewGroupManager<ReactToolbar> {
} }
} }
/**
* 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());
}
} }