Use new hybrid inheritance for NativeArray and descendants

Reviewed By: @andreicoman11

Differential Revision: D2523619

fb-gh-sync-id: 62382c16cbbeceec12763b3786676ecff783b651
This commit is contained in:
Mike Armstrong 2015-10-09 03:10:32 -07:00 committed by facebook-github-bot-3
parent 998ab1b1a4
commit fffae394c7
2 changed files with 45 additions and 17 deletions

View File

@ -8,29 +8,22 @@
namespace facebook {
namespace react {
struct NativeArray : public jni::HybridClass<NativeArray> {
class NativeArray : public jni::HybridClass<NativeArray> {
public:
static constexpr const char* kJavaDescriptor = "Lcom/facebook/react/bridge/NativeArray;";
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>) {
return makeCxxInstance();
}
// Whether this array has been added to another array or map and no longer has a valid array value
// Whether this array has been added to another array or map and no longer
// has a valid array value.
bool isConsumed = false;
folly::dynamic array = {};
folly::dynamic array;
jstring toString();
static void registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", NativeArray::initHybrid),
makeNativeMethod("toString", NativeArray::toString),
});
}
static void registerNatives();
protected:
friend HybridBase;
explicit NativeArray(folly::dynamic array);
};
__attribute__((visibility("default")))
jni::local_ref<NativeArray::jhybridobject>
createReadableNativeArrayWithContents(folly::dynamic array);
}}

View File

@ -0,0 +1,35 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#pragma once
#include "NativeArray.h"
namespace facebook {
namespace react {
class ReadableNativeArray : public jni::HybridClass<ReadableNativeArray, NativeArray> {
protected:
friend HybridBase;
explicit ReadableNativeArray(folly::dynamic array);
public:
static constexpr const char* kJavaDescriptor = "Lcom/facebook/react/bridge/ReadableNativeArray;";
static void mapException(const std::exception& ex);
jint getSize();
jboolean isNull(jint index);
jboolean getBoolean(jint index);
jint getInt(jint index);
jdouble getDouble(jint index);
// The lifetime of the const char* is the same as the underlying dynamic
// array. This is fine for converting back to Java, but other uses should be
// careful.
const char* getString(jint index);
jni::local_ref<jhybridobject> getArray(jint index);
jobject getMap(jint index);
jobject getType(jint index);
static void registerNatives();
};
}}