Skip to content

Commit

Permalink
fix: resource resolution for dynamic feature modules
Browse files Browse the repository at this point in the history
  • Loading branch information
rthic23 committed Jun 6, 2024
1 parent d8d8af8 commit a6667ed
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static Integer resolveResourcePath(Context context, @Nullable String reso
private static int resolveResource(Context context, String resourcePath) {
String[] pathTokens = resourcePath.split(PACKAGE_DELIMITER);

String packageName = context.getPackageName();
String packageName = ReactApplicationContext.PACKAGE_NAME == null ? context.getPackageName() : ReactApplicationContext.PACKAGE_NAME;
String resource = resourcePath;

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

String packageName = context.getPackageName();
String packageName = ReactApplicationContext.PACKAGE_NAME == null ? context.getPackageName() : ReactApplicationContext.PACKAGE_NAME;
String resourceName = path;

if (pathTokens.length > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public class ReactApplicationContext extends ReactContext {
public ReactApplicationContext(Context context) {
super(context.getApplicationContext());
}

public static String PACKAGE_NAME = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void initialize() {
// The application can register BlobProvider as a ContentProvider so that blobs are resolvable.
// If it does, it needs to tell us what authority was used via this string resource.
Resources resources = getReactApplicationContext().getResources();
String packageName = getReactApplicationContext().getPackageName();
String packageName = ReactApplicationContext.PACKAGE_NAME == null ? getReactApplicationContext().getPackageName() : ReactApplicationContext.PACKAGE_NAME;
int resourceId = resources.getIdentifier("blob_provider_authority", "string", packageName);
if (resourceId == 0) {
return MapBuilder.<String, Object>of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.graphics.drawable.Drawable;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReactApplicationContext;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -61,20 +62,20 @@ public int getResourceDrawableId(Context context, @Nullable String name) {
if (mResourceDrawableIdMap.containsKey(name)) {
return mResourceDrawableIdMap.get(name);
}
int id = context.getResources().getIdentifier(name, "drawable", context.getPackageName());
int id = context.getResources().getIdentifier(name, "drawable", ReactApplicationContext.PACKAGE_NAME == null ? context.getPackageName() : ReactApplicationContext.PACKAGE_NAME);
mResourceDrawableIdMap.put(name, id);
return id;
}
}

public @Nullable Drawable getResourceDrawable(Context context, @Nullable String name) {
int resId = getResourceDrawableId(context, name);
return resId > 0 ? context.getResources().getDrawable(resId) : null;
return resId != 0 ? context.getResources().getDrawable(resId) : null;
}

public Uri getResourceDrawableUri(Context context, @Nullable String name) {
int resId = getResourceDrawableId(context, name);
return resId > 0
return resId != 0
? new Uri.Builder().scheme(LOCAL_RESOURCE_SCHEME).path(String.valueOf(resId)).build()
: Uri.EMPTY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public ReadableMap getHeaders() {
return null;
}
name = name.toLowerCase(Locale.getDefault()).replace("-", "_");
int resId = context.getResources().getIdentifier(name, "drawable", context.getPackageName());
int resId = context.getResources().getIdentifier(name, "drawable", ReactApplicationContext.PACKAGE_NAME == null ? context.getPackageName() : ReactApplicationContext.PACKAGE_NAME);
return new Uri.Builder()
.scheme(UriUtil.LOCAL_RESOURCE_SCHEME)
.path(String.valueOf(resId))
Expand Down

0 comments on commit a6667ed

Please sign in to comment.