Skip to content

Commit a7a3fe2

Browse files
committed
fix: resource resolution for dynamic feature modules
1 parent 9ddcf58 commit a7a3fe2

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ColorPropConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public static Integer resolveResourcePath(Context context, @Nullable String reso
186186
private static int resolveResource(Context context, String resourcePath) {
187187
String[] pathTokens = resourcePath.split(PACKAGE_DELIMITER);
188188

189-
String packageName = context.getPackageName();
189+
String packageName = ReactApplicationContext.PACKAGE_NAME == null ? context.getPackageName() : ReactApplicationContext.PACKAGE_NAME;
190190
String resource = resourcePath;
191191

192192
if (pathTokens.length > 1) {
@@ -207,7 +207,7 @@ private static int resolveThemeAttribute(Context context, String resourcePath) {
207207
String path = resourcePath.replaceAll(ATTR_SEGMENT, "");
208208
String[] pathTokens = path.split(PACKAGE_DELIMITER);
209209

210-
String packageName = context.getPackageName();
210+
String packageName = ReactApplicationContext.PACKAGE_NAME == null ? context.getPackageName() : ReactApplicationContext.PACKAGE_NAME;
211211
String resourceName = path;
212212

213213
if (pathTokens.length > 1) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactApplicationContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ public abstract class ReactApplicationContext extends ReactContext {
2020
public ReactApplicationContext(Context context) {
2121
super(context.getApplicationContext());
2222
}
23+
24+
public static String PACKAGE_NAME = null;
2325
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/blob/BlobModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void initialize() {
152152
// The application can register BlobProvider as a ContentProvider so that blobs are resolvable.
153153
// If it does, it needs to tell us what authority was used via this string resource.
154154
Resources resources = getReactApplicationContext().getResources();
155-
String packageName = getReactApplicationContext().getPackageName();
155+
String packageName = ReactApplicationContext.PACKAGE_NAME == null ? getReactApplicationContext().getPackageName() : ReactApplicationContext.PACKAGE_NAME;
156156
int resourceId = resources.getIdentifier("blob_provider_authority", "string", packageName);
157157
if (resourceId == 0) {
158158
return MapBuilder.<String, Object>of();

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/imagehelper/ResourceDrawableIdHelper.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package com.facebook.react.views.imagehelper
1010
import android.content.Context
1111
import android.graphics.drawable.Drawable
1212
import android.net.Uri
13+
import com.facebook.react.bridge.ReactApplicationContext;
1314
import androidx.core.content.res.ResourcesCompat
1415
import javax.annotation.concurrent.ThreadSafe
1516

@@ -42,19 +43,19 @@ public class ResourceDrawableIdHelper private constructor() {
4243
}
4344

4445
private fun addDrawableId(context: Context, normalizedName: String): Int {
45-
val newId = context.resources.getIdentifier(normalizedName, "drawable", context.packageName)
46+
val newId = context.resources.getIdentifier(normalizedName, "drawable", if (ReactApplicationContext.PACKAGE_NAME == null) context.packageName else ReactApplicationContext.PACKAGE_NAME)
4647
resourceDrawableIdMap[normalizedName] = newId
4748
return newId
4849
}
4950

5051
public fun getResourceDrawable(context: Context, name: String?): Drawable? {
5152
val resId = getResourceDrawableId(context, name)
52-
return if (resId > 0) ResourcesCompat.getDrawable(context.resources, resId, null) else null
53+
return if (resId != 0) ResourcesCompat.getDrawable(context.resources, resId, null) else null
5354
}
5455

5556
public fun getResourceDrawableUri(context: Context, name: String?): Uri {
5657
val resId = getResourceDrawableId(context, name)
57-
return if (resId > 0) {
58+
return if (resId != 0) {
5859
Uri.Builder().scheme(LOCAL_RESOURCE_SCHEME).path(resId.toString()).build()
5960
} else {
6061
Uri.EMPTY

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/frescosupport/FrescoBasedReactTextInlineImageShadowNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.facebook.react.bridge.ReadableArray;
1919
import com.facebook.react.bridge.ReadableMap;
2020
import com.facebook.react.bridge.ReadableType;
21+
import com.facebook.react.bridge.ReactApplicationContext;
2122
import com.facebook.react.common.ReactConstants;
2223
import com.facebook.react.uimanager.ViewProps;
2324
import com.facebook.react.uimanager.annotations.ReactProp;
@@ -119,7 +120,7 @@ public ReadableMap getHeaders() {
119120
return null;
120121
}
121122
name = name.toLowerCase(Locale.getDefault()).replace("-", "_");
122-
int resId = context.getResources().getIdentifier(name, "drawable", context.getPackageName());
123+
int resId = context.getResources().getIdentifier(name, "drawable", ReactApplicationContext.PACKAGE_NAME == null ? context.getPackageName() : ReactApplicationContext.PACKAGE_NAME);
123124
return new Uri.Builder()
124125
.scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
125126
.path(String.valueOf(resId))

0 commit comments

Comments
 (0)