File tree Expand file tree Collapse file tree
ReactAndroid/src/main/java/com/facebook/react/bridge Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313import com .facebook .proguard .annotations .DoNotStrip ;
1414import com .facebook .soloader .SoLoader ;
1515
16+ import java .util .ArrayList ;
17+
1618/**
1719 * Implementation of a NativeArray that allows read-only access to its members. This will generally
1820 * be constructed and filled in native code so you shouldn't construct one yourself.
@@ -46,4 +48,34 @@ protected ReadableNativeArray(HybridData hybridData) {
4648 public native ReadableNativeMap getMap (int index );
4749 @ Override
4850 public native ReadableType getType (int index );
51+
52+ public ArrayList <Object > toArrayList () {
53+ ArrayList <Object > arrayList = new ArrayList <>();
54+
55+ for (int i = 0 ; i < this .size (); i ++) {
56+ switch (getType (i )) {
57+ case Null :
58+ arrayList .add (null );
59+ break ;
60+ case Boolean :
61+ arrayList .add (getBoolean (i ));
62+ break ;
63+ case Number :
64+ arrayList .add (getDouble (i ));
65+ break ;
66+ case String :
67+ arrayList .add (getString (i ));
68+ break ;
69+ case Map :
70+ arrayList .add (getMap (i ).toHashMap ());
71+ break ;
72+ case Array :
73+ arrayList .add (getArray (i ).toArrayList ());
74+ break ;
75+ default :
76+ throw new IllegalArgumentException ("Could not convert object at index: " + i + "." );
77+ }
78+ }
79+ return arrayList ;
80+ }
4981}
Original file line number Diff line number Diff line change 1313import com .facebook .proguard .annotations .DoNotStrip ;
1414import com .facebook .soloader .SoLoader ;
1515
16+ import java .util .HashMap ;
17+
18+
1619/**
1720 * Implementation of a read-only map in native memory. This will generally be constructed and filled
1821 * in native code so you shouldn't construct one yourself.
@@ -48,6 +51,35 @@ public ReadableMapKeySetIterator keySetIterator() {
4851 return new ReadableNativeMapKeySetIterator (this );
4952 }
5053
54+ public HashMap <String , Object >toHashMap () {
55+ ReadableMapKeySetIterator iterator = keySetIterator ();
56+ HashMap <String , Object > hashMap = new HashMap <>();
57+
58+ while (iterator .hasNextKey ()) {
59+ String key = iterator .nextKey ();
60+ switch (getType (key )) {
61+ case Null :
62+ hashMap .put (key , null );
63+ break ;
64+ case Boolean :
65+ hashMap .put (key , getBoolean (key ));
66+ break ;
67+ case Number :
68+ hashMap .put (key , getDouble (key ));
69+ break ;
70+ case Map :
71+ hashMap .put (key , getMap (key ).toHashMap ());
72+ break ;
73+ case Array :
74+ hashMap .put (key , getArray (key ).toArrayList ());
75+ break ;
76+ default :
77+ throw new IllegalArgumentException ("Could not convert object with key: " + key + "." );
78+ }
79+ }
80+ return hashMap ;
81+ }
82+
5183 /**
5284 * Implementation of a {@link ReadableNativeMap} iterator in native memory.
5385 */
You can’t perform that action at this time.
0 commit comments