mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-11 22:40:37 +08:00
Add toArrayList and toHashMap methods for ReadableArray and ReadableMap. Fixes #4655
Summary:Context #4658 I kept the original commit and author. cc mkonicek Closes https://github.com/facebook/react-native/pull/6639 Differential Revision: D3126336 Pulled By: mkonicek fb-gh-sync-id: 5ae7b37f0eb1db355bb87076d621a405ff9c23c5 fbshipit-source-id: 5ae7b37f0eb1db355bb87076d621a405ff9c23c5
This commit is contained in:
committed by
Facebook Github Bot 6
parent
31bb85a210
commit
dc3836a9d3
@@ -13,6 +13,8 @@ import com.facebook.jni.HybridData;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Implementation of a NativeArray that allows read-only access to its members. This will generally
|
||||
* be constructed and filled in native code so you shouldn't construct one yourself.
|
||||
@@ -46,4 +48,34 @@ public class ReadableNativeArray extends NativeArray implements ReadableArray {
|
||||
public native ReadableNativeMap getMap(int index);
|
||||
@Override
|
||||
public native ReadableType getType(int index);
|
||||
|
||||
public ArrayList<Object> toArrayList() {
|
||||
ArrayList<Object> arrayList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < this.size(); i++) {
|
||||
switch (getType(i)) {
|
||||
case Null:
|
||||
arrayList.add(null);
|
||||
break;
|
||||
case Boolean:
|
||||
arrayList.add(getBoolean(i));
|
||||
break;
|
||||
case Number:
|
||||
arrayList.add(getDouble(i));
|
||||
break;
|
||||
case String:
|
||||
arrayList.add(getString(i));
|
||||
break;
|
||||
case Map:
|
||||
arrayList.add(getMap(i).toHashMap());
|
||||
break;
|
||||
case Array:
|
||||
arrayList.add(getArray(i).toArrayList());
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Could not convert object at index: " + i + ".");
|
||||
}
|
||||
}
|
||||
return arrayList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user