Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes for new arch on RN 74 #473

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SafeAreaContextModule(reactContext: ReactApplicationContext?) :
}

public override fun getTypedExportedConstants(): Map<String, Any> {
return MapBuilder.of<String, Any>("initialWindowMetrics", getInitialWindowMetrics())
return MapBuilder.of<String, Any>("initialWindowMetrics", getInitialWindowMetrics() as Any)
}

private fun getInitialWindowMetrics(): Map<String, Any>? {
Expand Down
8 changes: 5 additions & 3 deletions android/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -61,7 +63,7 @@ target_compile_options(
-DLOG_TAG=\"ReactNative\"
-fexceptions
-frtti
-std=c++17
-std=c++20
-Wall
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<const RNCSafeAreaViewShadowNode::ConcreteState>(
getState());
Expand All @@ -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<YGUnitPoint>(getEdgeValue(
edges.top,
stateData.insets.top,
(top.unit == YGUnitPoint ? top.value : 0)));
left = yoga::CompactValue::ofMaybe<YGUnitPoint>(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<YGUnitPoint>(getEdgeValue(
left.value().unwrapOrDefault(0)));
right.points(getEdgeValue(
edges.right,
stateData.insets.right,
(right.unit == YGUnitPoint ? right.value : 0)));
bottom = yoga::CompactValue::ofMaybe<YGUnitPoint>(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);
}
Expand Down
Loading