From 8cf8333433d8ed2f426e87141e36a52dcf880637 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Wed, 28 Feb 2024 16:55:28 +0100 Subject: [PATCH] fix: fixes for new arch on RN 74 (#473) * fix: fixes for new arch on RN 74 * fix: unused import * fix: proper cpp standard * fix: android changes * fix: build both archs on CI Android --- .github/workflows/android.yml | 4 +- .../safeareacontext/SafeAreaContextModule.kt | 2 +- android/src/main/jni/CMakeLists.txt | 8 +- .../RNCSafeAreaViewShadowNode.cpp | 110 +++++++++--------- 4 files changed, 65 insertions(+), 59 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 3e1883d0..6aad07b2 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -41,8 +41,8 @@ jobs: - name: Install example app dependencies run: yarn install working-directory: example - - name: Build android example app - run: ./gradlew assembleDebug + - name: Build android example app with new arch disabled + run: ./gradlew assembleDebug -PnewArchEnabled=false working-directory: example/android android-build-fabric: runs-on: ubuntu-latest diff --git a/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextModule.kt b/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextModule.kt index 8261d394..93c0c9c6 100644 --- a/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextModule.kt +++ b/android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaContextModule.kt @@ -14,7 +14,7 @@ class SafeAreaContextModule(reactContext: ReactApplicationContext?) : } public override fun getTypedExportedConstants(): Map { - return MapBuilder.of("initialWindowMetrics", getInitialWindowMetrics()) + return MapBuilder.of("initialWindowMetrics", getInitialWindowMetrics() as Any) } private fun getInitialWindowMetrics(): Map? { diff --git a/android/src/main/jni/CMakeLists.txt b/android/src/main/jni/CMakeLists.txt index c89c4fb4..4ee1c8fc 100644 --- a/android/src/main/jni/CMakeLists.txt +++ b/android/src/main/jni/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.13) -set(CMAKE_VERBOSE_MAKEFILE on) +set(CMAKE_VERBOSE_MAKEFILE ON) set(LIB_LITERAL safeareacontext) set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL}) @@ -12,7 +12,7 @@ set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/ add_compile_options( -fexceptions -frtti - -std=c++17 + -std=c++20 -Wall -Wpedantic -Wno-gnu-zero-variadic-macro-arguments @@ -50,6 +50,8 @@ target_link_libraries( react_render_debug react_render_graphics react_render_mapbuffer + react_render_componentregistry + react_utils rrc_view turbomodulejsijni yoga @@ -61,7 +63,7 @@ target_compile_options( -DLOG_TAG=\"ReactNative\" -fexceptions -frtti - -std=c++17 + -std=c++20 -Wall ) diff --git a/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.cpp b/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.cpp index b4bf4492..d79ea2e4 100644 --- a/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.cpp +++ b/common/cpp/react/renderer/components/safeareacontext/RNCSafeAreaViewShadowNode.cpp @@ -8,19 +8,19 @@ namespace facebook { namespace react { +using namespace yoga; + extern const char RNCSafeAreaViewComponentName[] = "RNCSafeAreaView"; -inline YGValue -valueFromEdges(yoga::Style::Edges edges, YGEdge edge, YGEdge axis) { - YGValue edgeValue = edges[edge]; - if (edgeValue.unit != YGUnitUndefined) { - return edgeValue; - } - YGValue axisValue = edges[axis]; - if (axisValue.unit != YGUnitUndefined) { - return axisValue; - } - return edges[YGEdgeAll]; +inline Style::Length +valueFromEdges(Style::Length edge, Style::Length axis, Style::Length defaultValue) { + if (edge.unit() != Unit::Undefined) { + return edge; + } + if (axis.unit() != Unit::Undefined) { + return axis; + } + return defaultValue; } inline float @@ -37,7 +37,7 @@ getEdgeValue(std::string edgeMode, float insetValue, float edgeValue) { void RNCSafeAreaViewShadowNode::adjustLayoutWithState() { ensureUnsealed(); - auto props = getConcreteProps(); + auto &props = getConcreteProps(); auto state = std::static_pointer_cast( getState()); @@ -47,69 +47,73 @@ void RNCSafeAreaViewShadowNode::adjustLayoutWithState() { // Get the current values for padding / margin. The only caveat here is that // percent values are not supported. Also might need to add support for start // / end. - YGValue top, left, right, bottom; + Style::Length top, left, right, bottom; if (props.mode == RNCSafeAreaViewMode::Padding) { - top = valueFromEdges(props.yogaStyle.padding(), YGEdgeTop, YGEdgeVertical); + auto defaultPadding = props.yogaStyle.padding(Edge::All); + top = valueFromEdges(props.yogaStyle.padding(Edge::Top), props.yogaStyle.padding(Edge::Vertical), defaultPadding); left = - valueFromEdges(props.yogaStyle.padding(), YGEdgeLeft, YGEdgeHorizontal); + valueFromEdges(props.yogaStyle.padding(Edge::Left), props.yogaStyle.padding(Edge::Horizontal), defaultPadding); bottom = - valueFromEdges(props.yogaStyle.padding(), YGEdgeBottom, YGEdgeVertical); + valueFromEdges(props.yogaStyle.padding(Edge::Bottom), props.yogaStyle.padding(Edge::Vertical), defaultPadding); right = valueFromEdges( - props.yogaStyle.padding(), YGEdgeRight, YGEdgeHorizontal); + props.yogaStyle.padding(Edge::Right), props.yogaStyle.padding(Edge::Horizontal), defaultPadding); } else { - top = valueFromEdges(props.yogaStyle.margin(), YGEdgeTop, YGEdgeVertical); + auto defaultMargin = props.yogaStyle.margin(Edge::All); + top = valueFromEdges(props.yogaStyle.margin(Edge::Top), props.yogaStyle.margin(Edge::Vertical), defaultMargin); left = - valueFromEdges(props.yogaStyle.margin(), YGEdgeLeft, YGEdgeHorizontal); + valueFromEdges(props.yogaStyle.margin(Edge::Left), props.yogaStyle.margin(Edge::Horizontal), defaultMargin); bottom = - valueFromEdges(props.yogaStyle.margin(), YGEdgeBottom, YGEdgeVertical); + valueFromEdges(props.yogaStyle.margin(Edge::Bottom), props.yogaStyle.margin(Edge::Vertical), defaultMargin); right = - valueFromEdges(props.yogaStyle.margin(), YGEdgeRight, YGEdgeHorizontal); + valueFromEdges(props.yogaStyle.margin(Edge::Right), props.yogaStyle.margin(Edge::Horizontal), defaultMargin); } - top = yoga::CompactValue::ofMaybe(getEdgeValue( - edges.top, - stateData.insets.top, - (top.unit == YGUnitPoint ? top.value : 0))); - left = yoga::CompactValue::ofMaybe(getEdgeValue( + top.points(getEdgeValue( + edges.top, + stateData.insets.top, + top.value().unwrapOrDefault(0) + ) + ); + left.points(getEdgeValue( edges.left, stateData.insets.left, - (left.unit == YGUnitPoint ? left.value : 0))); - right = yoga::CompactValue::ofMaybe(getEdgeValue( + left.value().unwrapOrDefault(0))); + right.points(getEdgeValue( edges.right, stateData.insets.right, - (right.unit == YGUnitPoint ? right.value : 0))); - bottom = yoga::CompactValue::ofMaybe(getEdgeValue( + right.value().unwrapOrDefault(0))); + bottom.points(getEdgeValue( edges.bottom, stateData.insets.bottom, - (bottom.unit == YGUnitPoint ? bottom.value : 0))); + bottom.value().unwrapOrDefault(0))); yoga::Style adjustedStyle = getConcreteProps().yogaStyle; if (props.mode == RNCSafeAreaViewMode::Padding) { - adjustedStyle.padding()[YGEdgeTop] = top; - adjustedStyle.padding()[YGEdgeLeft] = left; - adjustedStyle.padding()[YGEdgeRight] = right; - adjustedStyle.padding()[YGEdgeBottom] = bottom; + adjustedStyle.setPadding(Edge::Top, top); + adjustedStyle.setPadding(Edge::Left, left); + adjustedStyle.setPadding(Edge::Right, right); + adjustedStyle.setPadding(Edge::Bottom, bottom); } else { - adjustedStyle.margin()[YGEdgeTop] = top; - adjustedStyle.margin()[YGEdgeLeft] = left; - adjustedStyle.margin()[YGEdgeRight] = right; - adjustedStyle.margin()[YGEdgeBottom] = bottom; + adjustedStyle.setMargin(Edge::Top, top); + adjustedStyle.setMargin(Edge::Left, left); + adjustedStyle.setMargin(Edge::Right, right); + adjustedStyle.setMargin(Edge::Bottom, bottom); } - auto currentStyle = yogaNode_.getStyle(); - if (adjustedStyle.padding()[YGEdgeTop] != currentStyle.padding()[YGEdgeTop] || - adjustedStyle.padding()[YGEdgeLeft] != - currentStyle.padding()[YGEdgeLeft] || - adjustedStyle.padding()[YGEdgeRight] != - currentStyle.padding()[YGEdgeRight] || - adjustedStyle.padding()[YGEdgeBottom] != - currentStyle.padding()[YGEdgeBottom] || - adjustedStyle.margin()[YGEdgeTop] != currentStyle.margin()[YGEdgeTop] || - adjustedStyle.margin()[YGEdgeLeft] != currentStyle.margin()[YGEdgeLeft] || - adjustedStyle.margin()[YGEdgeRight] != - currentStyle.margin()[YGEdgeRight] || - adjustedStyle.margin()[YGEdgeBottom] != - currentStyle.margin()[YGEdgeBottom]) { + auto currentStyle = yogaNode_.style(); + if (adjustedStyle.padding(Edge::Top) != currentStyle.padding(Edge::Top) || + adjustedStyle.padding(Edge::Left) != + currentStyle.padding(Edge::Left) || + adjustedStyle.padding(Edge::Right) != + currentStyle.padding(Edge::Right) || + adjustedStyle.padding(Edge::Bottom) != + currentStyle.padding(Edge::Bottom) || + adjustedStyle.margin(Edge::Top) != currentStyle.margin(Edge::Top) || + adjustedStyle.margin(Edge::Left) != currentStyle.margin(Edge::Left) || + adjustedStyle.margin(Edge::Right) != + currentStyle.margin(Edge::Right) || + adjustedStyle.margin(Edge::Bottom) != + currentStyle.margin(Edge::Bottom)) { yogaNode_.setStyle(adjustedStyle); yogaNode_.setDirty(true); }