Skip to content

Commit

Permalink
Update react-native-safe-area-context to 4.6.3 (expo#23026)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsapeta authored Jun 22, 2023
1 parent 5e530f5 commit 64f1b87
Show file tree
Hide file tree
Showing 25 changed files with 236 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@

/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
* This code was generated by
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
* <p>Do not edit this file as changes may cause incorrect behavior and will be lost once the code
* is regenerated.
*
* @generated by codegen project: GenerateModuleJavaSpec.js
*
* @nolint
*/

package versioned.host.exp.exponent.modules.api.safeareacontext;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
Expand All @@ -25,7 +22,8 @@
import java.util.Set;
import javax.annotation.Nullable;

public abstract class NativeSafeAreaContextSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public abstract class NativeSafeAreaContextSpec extends ReactContextBaseJavaModule
implements ReactModuleWithSpec, TurboModule {
public NativeSafeAreaContextSpec(ReactApplicationContext reactContext) {
super(reactContext);
}
Expand All @@ -38,19 +36,19 @@ public NativeSafeAreaContextSpec(ReactApplicationContext reactContext) {
Map<String, Object> constants = getTypedExportedConstants();
if (ReactBuildConfig.DEBUG || ReactBuildConfig.IS_INTERNAL_BUILD) {
Set<String> obligatoryFlowConstants = new HashSet<>();
Set<String> optionalFlowConstants = new HashSet<>(Arrays.asList(
"initialWindowMetrics"
));
Set<String> optionalFlowConstants = new HashSet<>(Arrays.asList("initialWindowMetrics"));
Set<String> undeclaredConstants = new HashSet<>(constants.keySet());
undeclaredConstants.removeAll(obligatoryFlowConstants);
undeclaredConstants.removeAll(optionalFlowConstants);
if (!undeclaredConstants.isEmpty()) {
throw new IllegalStateException(String.format("Native Module Flow doesn't declare constants: %s", undeclaredConstants));
throw new IllegalStateException(
String.format("Native Module Flow doesn't declare constants: %s", undeclaredConstants));
}
undeclaredConstants = obligatoryFlowConstants;
undeclaredConstants.removeAll(constants.keySet());
if (!undeclaredConstants.isEmpty()) {
throw new IllegalStateException(String.format("Native Module doesn't fill in constants: %s", undeclaredConstants));
throw new IllegalStateException(
String.format("Native Module doesn't fill in constants: %s", undeclaredConstants));
}
}
return constants;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/

* This code was generated by
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* <p>Do not edit this file as changes may cause incorrect behavior and will be lost once the code
* is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/
package versioned.host.exp.exponent.modules.api.safeareacontext;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;

public class RNCSafeAreaProviderManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & RNCSafeAreaProviderManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public class RNCSafeAreaProviderManagerDelegate<
T extends View,
U extends BaseViewManagerInterface<T> & RNCSafeAreaProviderManagerInterface<T>>
extends BaseViewManagerDelegate<T, U> {
public RNCSafeAreaProviderManagerDelegate(U viewManager) {
super(viewManager);
}

@Override
public void setProperty(T view, String propName, @Nullable Object value) {
super.setProperty(view, propName, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/

* This code was generated by
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* <p>Do not edit this file as changes may cause incorrect behavior and will be lost once the code
* is regenerated.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/
package versioned.host.exp.exponent.modules.api.safeareacontext;

import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/

* This code was generated by
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* <p>Do not edit this file as changes may cause incorrect behavior and will be lost once the code
* is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/
package versioned.host.exp.exponent.modules.api.safeareacontext;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;

public class RNCSafeAreaViewManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & RNCSafeAreaViewManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public class RNCSafeAreaViewManagerDelegate<
T extends View, U extends BaseViewManagerInterface<T> & RNCSafeAreaViewManagerInterface<T>>
extends BaseViewManagerDelegate<T, U> {
public RNCSafeAreaViewManagerDelegate(U viewManager) {
super(viewManager);
}

@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case "mode":
mViewManager.setMode(view, (String) value);
break;
case "edges":
mViewManager.setEdges(view, (ReadableArray) value);
mViewManager.setEdges(view, (ReadableMap) value);
break;
default:
super.setProperty(view, propName, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/

* This code was generated by
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* <p>Do not edit this file as changes may cause incorrect behavior and will be lost once the code
* is regenerated.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/
package versioned.host.exp.exponent.modules.api.safeareacontext;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;

public interface RNCSafeAreaViewManagerInterface<T extends View> {
void setMode(T view, @Nullable String value);
void setEdges(T view, @Nullable ReadableArray value);

void setEdges(T view, @Nullable ReadableMap value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SafeAreaView(context: Context?) :
ReactViewGroup(context), ViewTreeObserver.OnPreDrawListener, HasFabricViewStateManager {
private var mMode = SafeAreaViewMode.PADDING
private var mInsets: EdgeInsets? = null
private var mEdges: EnumSet<SafeAreaViewEdges>? = null
private var mEdges: SafeAreaViewEdges? = null
private var mProviderView: View? = null
private val mFabricViewStateManager = FabricViewStateManager()

Expand All @@ -30,7 +30,13 @@ class SafeAreaView(context: Context?) :
private fun updateInsets() {
val insets = mInsets
if (insets != null) {
val edges = mEdges ?: EnumSet.allOf(SafeAreaViewEdges::class.java)
val edges =
mEdges
?: SafeAreaViewEdges(
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE)
if (mFabricViewStateManager.hasStateWrapper()) {
mFabricViewStateManager.setState {
val map = Arguments.createMap()
Expand All @@ -43,8 +49,10 @@ class SafeAreaView(context: Context?) :
val uiManager = reactContext.getNativeModule(UIManagerModule::class.java)
if (uiManager != null) {
uiManager.setViewLocalData(id, localData)
// Sadly there doesn't seem to be a way to properly dirty a yoga node from java, so if we are in
// the middle of a layout, we need to recompute it. There is also no way to know whether we
// Sadly there doesn't seem to be a way to properly dirty a yoga node from java, so if we
// are in
// the middle of a layout, we need to recompute it. There is also no way to know whether
// we
// are in the middle of a layout so always do it.
reactContext.runOnNativeModulesQueueThread {
uiManager.uiImplementation.dispatchViewUpdates(-1)
Expand Down Expand Up @@ -96,7 +104,7 @@ class SafeAreaView(context: Context?) :
updateInsets()
}

fun setEdges(edges: EnumSet<SafeAreaViewEdges>?) {
fun setEdges(edges: SafeAreaViewEdges) {
mEdges = edges
updateInsets()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package versioned.host.exp.exponent.modules.api.safeareacontext

enum class SafeAreaViewEdges {
TOP,
RIGHT,
BOTTOM,
LEFT
import java.util.*

enum class SafeAreaViewEdgeModes {
OFF,
ADDITIVE,
MAXIMUM
}

data class SafeAreaViewEdges(
val top: SafeAreaViewEdgeModes,
val right: SafeAreaViewEdgeModes,
val bottom: SafeAreaViewEdgeModes,
val left: SafeAreaViewEdgeModes
)

class Safe
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import java.util.*
data class SafeAreaViewLocalData(
val insets: EdgeInsets,
val mode: SafeAreaViewMode,
val edges: EnumSet<SafeAreaViewEdges>
val edges: SafeAreaViewEdges,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package versioned.host.exp.exponent.modules.api.safeareacontext

import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.ReactStylesDiffMap
import com.facebook.react.uimanager.StateWrapper
Expand Down Expand Up @@ -39,26 +39,23 @@ class SafeAreaViewManager : ReactViewManager(), RNCSafeAreaViewManagerInterface<
}

@ReactProp(name = "edges")
override fun setEdges(view: SafeAreaView, propList: ReadableArray?) {
val edges = EnumSet.noneOf(SafeAreaViewEdges::class.java)
override fun setEdges(view: SafeAreaView, propList: ReadableMap?) {
if (propList != null) {
for (i in 0 until propList.size()) {
when (propList.getString(i)) {
"top" -> {
edges.add(SafeAreaViewEdges.TOP)
}
"right" -> {
edges.add(SafeAreaViewEdges.RIGHT)
}
"bottom" -> {
edges.add(SafeAreaViewEdges.BOTTOM)
}
"left" -> {
edges.add(SafeAreaViewEdges.LEFT)
}
}
}
view.setEdges(edges)
view.setEdges(
SafeAreaViewEdges(
top = propList.getString("top")?.let { SafeAreaViewEdgeModes.valueOf(it.uppercase()) }
?: SafeAreaViewEdgeModes.OFF,
right =
propList.getString("right")?.let { SafeAreaViewEdgeModes.valueOf(it.uppercase()) }
?: SafeAreaViewEdgeModes.OFF,
bottom =
propList.getString("bottom")?.let {
SafeAreaViewEdgeModes.valueOf(it.uppercase())
}
?: SafeAreaViewEdgeModes.OFF,
left =
propList.getString("left")?.let { SafeAreaViewEdgeModes.valueOf(it.uppercase()) }
?: SafeAreaViewEdgeModes.OFF))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.facebook.react.bridge.Dynamic
import com.facebook.react.bridge.ReadableType
import com.facebook.react.uimanager.*
import com.facebook.react.uimanager.annotations.ReactPropGroup
import com.facebook.yoga.YogaNode
import kotlin.math.max

class SafeAreaViewShadowNode : LayoutShadowNode() {
private var mLocalData: SafeAreaViewLocalData? = null
Expand Down Expand Up @@ -65,20 +65,30 @@ class SafeAreaViewShadowNode : LayoutShadowNode() {
left = PixelUtil.toPixelFromDIP(left)
val edges = localData.edges
val insets = localData.insets
val insetTop: Float = if (edges.contains(SafeAreaViewEdges.TOP)) insets.top else 0.0f
val insetRight: Float = if (edges.contains(SafeAreaViewEdges.RIGHT)) insets.right else 0.0f
val insetBottom: Float = if (edges.contains(SafeAreaViewEdges.BOTTOM)) insets.bottom else 0.0f
val insetLeft: Float = if (edges.contains(SafeAreaViewEdges.LEFT)) insets.left else 0.0f
if (localData.mode == SafeAreaViewMode.PADDING) {
super.setPadding(Spacing.TOP, insetTop + top)
super.setPadding(Spacing.RIGHT, insetRight + right)
super.setPadding(Spacing.BOTTOM, insetBottom + bottom)
super.setPadding(Spacing.LEFT, insetLeft + left)
super.setPadding(Spacing.TOP, getEdgeValue(edges.top, insets.top, top))
super.setPadding(Spacing.RIGHT, getEdgeValue(edges.right, insets.right, right))
super.setPadding(Spacing.BOTTOM, getEdgeValue(edges.bottom, insets.bottom, bottom))
super.setPadding(Spacing.LEFT, getEdgeValue(edges.left, insets.left, left))
} else {
super.setMargin(Spacing.TOP, insetTop + top)
super.setMargin(Spacing.RIGHT, insetRight + right)
super.setMargin(Spacing.BOTTOM, insetBottom + bottom)
super.setMargin(Spacing.LEFT, insetLeft + left)
super.setMargin(Spacing.TOP, getEdgeValue(edges.top, insets.top, top))
super.setMargin(Spacing.RIGHT, getEdgeValue(edges.right, insets.right, right))
super.setMargin(Spacing.BOTTOM, getEdgeValue(edges.bottom, insets.bottom, bottom))
super.setMargin(Spacing.LEFT, getEdgeValue(edges.left, insets.left, left))
}
}

private fun getEdgeValue(
edgeMode: SafeAreaViewEdgeModes,
insetValue: Float,
edgeValue: Float
): Float {
if (edgeMode == SafeAreaViewEdgeModes.OFF) {
return edgeValue
} else if (edgeMode == SafeAreaViewEdgeModes.MAXIMUM) {
return max(insetValue, edgeValue)
} else {
return insetValue + edgeValue
}
}

Expand Down
4 changes: 2 additions & 2 deletions apps/bare-expo/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ PODS:
- React-Core
- react-native-pager-view (6.2.0):
- React-Core
- react-native-safe-area-context (4.5.3):
- react-native-safe-area-context (4.6.3):
- RCT-Folly
- RCTRequired
- RCTTypeSafety
Expand Down Expand Up @@ -1479,7 +1479,7 @@ SPEC CHECKSUMS:
React-logger: 454ffb01980778a43b0153ee98721d0275b56616
react-native-netinfo: ccbe1085dffd16592791d550189772e13bf479e2
react-native-pager-view: 0ccb8bf60e2ebd38b1f3669fa3650ecce81db2df
react-native-safe-area-context: b8979f5eda6ed5903d4dbc885be3846ea3daa753
react-native-safe-area-context: 36cc67648134e89465663b8172336a19eeda493d
react-native-segmented-control: 0e4b5d93911e2234f110057df2b41738b326ab3e
react-native-slider: 33b8d190b59d4f67a541061bb91775d53d617d9d
react-native-view-shot: 705f999ac2a24e4e6c909c0ca65c732ed33ca2ff
Expand Down
Loading

0 comments on commit 64f1b87

Please sign in to comment.