mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Petterh/support parcelable array args (#26379)
Summary: `ReactRootView.startReactApplication` takes a `Bundle` argument called `initialProperties`. This is translated to a `ReadableMap` via `Arguments.fromBundle`. If the bundle contains an array of bundles, this gets translated by `Arguments.fromArray`. If the bundle was passed from one activity to another via intent extras, however, there is a problem. After the bundle has been marshaled and unmarshaled, the array of `Bundle`s come out the other end as an arrap of `Parcelable`s, although each array element remains a `Bundle`. This results in an "Unknown array type" exception. This PR fixes this by adding support for `Parcelable` arrays – provided they contain only members of type `Bundle`. ## Changelog [Android] [Fixed] - Don't throw "Unknown array type" exception when passing serialized bundle arrays in ReactRootView.startReactApplication's initialProperties parameter Pull Request resolved: https://github.com/facebook/react-native/pull/26379 Test Plan: Added test class `ArgumentsTest`. The test method `testFromMarshaledBundle` fails when used on the old version of `Arguments`. Differential Revision: D17661203 Pulled By: cpojer fbshipit-source-id: 63612d78f49bdf9cc53f6f21ae883dba6cebce84
This commit is contained in:
committed by
Facebook Github Bot
parent
e1d89fbd9d
commit
4b9350061f
@@ -7,6 +7,8 @@
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.AbstractList;
|
||||
@@ -218,6 +220,14 @@ public class Arguments {
|
||||
for (boolean v : (boolean[]) array) {
|
||||
catalystArray.pushBoolean(v);
|
||||
}
|
||||
} else if (array instanceof Parcelable[]) {
|
||||
for (Parcelable v : (Parcelable[]) array) {
|
||||
if (v instanceof Bundle) {
|
||||
catalystArray.pushMap(fromBundle((Bundle) v));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected array member type " + v.getClass());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown array type " + array.getClass());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user