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(#439): remove deprecated FabricViewStateManager class usage #462

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -30,6 +30,7 @@ class SafeAreaContextPackage : TurboReactPackage() {
moduleClass.name,
true,
reactModule.needsEagerInit,
/** TODO remove the parameter once support for RN < 0.73 is dropped */
reactModule.hasConstants,
reactModule.isCxxModule,
TurboModule::class.java.isAssignableFrom(moduleClass))
Expand Down
27 changes: 14 additions & 13 deletions android/src/main/java/com/th3rdwave/safeareacontext/SafeAreaView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,28 @@ import android.util.Log
import android.view.View
import android.view.ViewTreeObserver
import com.facebook.react.bridge.Arguments
import com.facebook.react.uimanager.FabricViewStateManager
import com.facebook.react.uimanager.FabricViewStateManager.HasFabricViewStateManager
import com.facebook.react.uimanager.StateWrapper
import com.facebook.react.uimanager.UIManagerModule
import com.facebook.react.views.view.ReactViewGroup
import java.util.*
import java.util.concurrent.locks.ReentrantLock
import kotlin.concurrent.withLock

private const val MAX_WAIT_TIME_NANO = 500000000L // 500ms

class SafeAreaView(context: Context?) :
ReactViewGroup(context), ViewTreeObserver.OnPreDrawListener, HasFabricViewStateManager {
ReactViewGroup(context), ViewTreeObserver.OnPreDrawListener {
private var mMode = SafeAreaViewMode.PADDING
private var mInsets: EdgeInsets? = null
private var mEdges: SafeAreaViewEdges? = null
private var mProviderView: View? = null
private val mFabricViewStateManager = FabricViewStateManager()
private var mStateWrapper: StateWrapper? = null

override fun getFabricViewStateManager(): FabricViewStateManager {
return mFabricViewStateManager
fun getStateWrapper(): StateWrapper? {
return mStateWrapper
}

fun setStateWrapper(stateWrapper: StateWrapper?) {
mStateWrapper = stateWrapper
}

private fun updateInsets() {
Expand All @@ -37,12 +39,11 @@ class SafeAreaView(context: Context?) :
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE,
SafeAreaViewEdgeModes.ADDITIVE)
if (mFabricViewStateManager.hasStateWrapper()) {
mFabricViewStateManager.setState {
val map = Arguments.createMap()
map.putMap("insets", edgeInsetsToJsMap(insets))
map
}
val stateWrapper = getStateWrapper()
if (stateWrapper != null) {
val map = Arguments.createMap()
map.putMap("insets", edgeInsetsToJsMap(insets))
stateWrapper.updateState(map)
} else {
val localData = SafeAreaViewLocalData(insets = insets, mode = mMode, edges = edges)
val reactContext = getReactContext(this)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.th3rdwave.safeareacontext

import java.util.*

enum class SafeAreaViewEdgeModes {
OFF,
ADDITIVE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.th3rdwave.safeareacontext

import java.util.*

data class SafeAreaViewLocalData(
val insets: EdgeInsets,
val mode: SafeAreaViewMode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.RNCSafeAreaViewManagerInterface
import com.facebook.react.views.view.ReactViewGroup
import com.facebook.react.views.view.ReactViewManager
import java.util.*

@ReactModule(name = SafeAreaViewManager.REACT_CLASS)
class SafeAreaViewManager : ReactViewManager(), RNCSafeAreaViewManagerInterface<SafeAreaView> {
Expand Down Expand Up @@ -64,7 +63,7 @@ class SafeAreaViewManager : ReactViewManager(), RNCSafeAreaViewManagerInterface<
props: ReactStylesDiffMap?,
stateWrapper: StateWrapper?
): Any? {
(view as SafeAreaView).fabricViewStateManager.setStateWrapper(stateWrapper)
(view as SafeAreaView).setStateWrapper(stateWrapper)
return null
}

Expand Down
Loading