Permalink
Browse files

Remove appcompat dep from react/views/toolbar

Reviewed By: AaaChiuuu

Differential Revision: D5651764

fbshipit-source-id: c8cf730bf2086d205a43a535f3f12ae2af0caa5f
  • Loading branch information...
ayc1 authored and facebook-github-bot committed Aug 21, 2017
1 parent 73f1790 commit c3b47e55238b7f40e2a1cdff3dc41b40ec380dab
@@ -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"),
@@ -9,19 +9,13 @@
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;
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.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 boolean needsCustomLayoutForChildren() {
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 boolean needsCustomLayoutForChildren() {
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 @@ private static void recycleQuietly(@Nullable TypedArray style) {
}
}
/**
* 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());
}
}

0 comments on commit c3b47e5

Please sign in to comment.