Skip to content

Commit 4132f6e

Browse files
committed
Add conditional on android
1 parent 2237936 commit 4132f6e

2 files changed

Lines changed: 44 additions & 35 deletions

File tree

packages/react-native-gesture-handler/android/src/main/jni/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
project(GestureHandler)
22
cmake_minimum_required(VERSION 3.9.0)
33

4+
string(
5+
APPEND
6+
CMAKE_CXX_FLAGS
7+
" -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}")
8+
49
set(CMAKE_VERBOSE_MAKEFILE ON)
510
if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 73)
611
set(CMAKE_CXX_STANDARD 20)

packages/react-native-gesture-handler/android/src/main/jni/cpp-adapter.cpp

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,47 @@ using namespace facebook;
77
using namespace react;
88

99
void decorateRuntime(jsi::Runtime &runtime) {
10-
auto isViewFlatteningDisabled = jsi::Function::createFromHostFunction(
11-
runtime,
12-
jsi::PropNameID::forAscii(runtime, "isViewFlatteningDisabled"),
13-
1,
14-
[](jsi::Runtime &runtime,
15-
const jsi::Value &thisValue,
16-
const jsi::Value *arguments,
17-
size_t count) -> jsi::Value {
18-
if (!arguments[0].isObject()) {
19-
return jsi::Value::null();
20-
}
21-
22-
auto shadowNode = Bridging<std::shared_ptr<const ShadowNode>>::fromJs(
23-
runtime, arguments[0]);
24-
25-
bool isViewFlatteningDisabled = shadowNode->getTraits().check(
26-
ShadowNodeTraits::FormsStackingContext);
27-
28-
// This is done using component names instead of type checking because
29-
// of duplicate symbols for RN types, which prevent RTTI from working.
30-
const char *componentName = shadowNode->getComponentName();
31-
bool isTextComponent = strcmp(componentName, "Paragraph") == 0 ||
32-
strcmp(componentName, "Text") == 0;
33-
34-
return jsi::Value(isViewFlatteningDisabled || isTextComponent);
35-
});
36-
runtime.global().setProperty(
37-
runtime, "isViewFlatteningDisabled", std::move(isViewFlatteningDisabled));
10+
auto isViewFlatteningDisabled = jsi::Function::createFromHostFunction(
11+
runtime,
12+
jsi::PropNameID::forAscii(runtime, "isViewFlatteningDisabled"),
13+
1,
14+
[](jsi::Runtime &runtime,
15+
const jsi::Value &thisValue,
16+
const jsi::Value *arguments,
17+
size_t count) -> jsi::Value {
18+
if (!arguments[0].isObject()) {
19+
return jsi::Value::null();
20+
}
21+
22+
#if REACT_NATIVE_MINOR_VERSION >= 81
23+
auto shadowNode = Bridging<std::shared_ptr<const ShadowNode>>::fromJs(
24+
runtime, arguments[0]);
25+
#else
26+
auto shadowNode = shadowNodeFromValue(runtime, arguments[0]);
27+
#endif
28+
29+
bool isViewFlatteningDisabled = shadowNode->getTraits().check(
30+
ShadowNodeTraits::FormsStackingContext);
31+
32+
// This is done using component names instead of type checking because
33+
// of duplicate symbols for RN types, which prevent RTTI from working.
34+
const char *componentName = shadowNode->getComponentName();
35+
bool isTextComponent = strcmp(componentName, "Paragraph") == 0 ||
36+
strcmp(componentName, "Text") == 0;
37+
38+
return jsi::Value(isViewFlatteningDisabled || isTextComponent);
39+
});
40+
runtime.global().setProperty(
41+
runtime, "isViewFlatteningDisabled", std::move(isViewFlatteningDisabled));
3842
}
3943

4044
extern "C" JNIEXPORT void JNICALL
4145
Java_com_swmansion_gesturehandler_react_RNGestureHandlerModule_decorateRuntime(
42-
JNIEnv *env,
43-
jobject clazz,
44-
jlong jsiPtr) {
45-
jsi::Runtime *runtime = reinterpret_cast<jsi::Runtime *>(jsiPtr);
46-
if (runtime) {
47-
decorateRuntime(*runtime);
48-
}
46+
JNIEnv *env,
47+
jobject clazz,
48+
jlong jsiPtr) {
49+
jsi::Runtime *runtime = reinterpret_cast<jsi::Runtime *>(jsiPtr);
50+
if (runtime) {
51+
decorateRuntime(*runtime);
52+
}
4953
}

0 commit comments

Comments
 (0)