Skip to content
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 @@ -23,24 +23,19 @@ abstract class FabricEnabledHeaderConfigViewGroup(
mStateWrapper = wrapper
}

fun updatePaddings(
paddingStart: Int,
paddingEnd: Int,
) {
// Do nothing on Fabric. This method is used only on Paper.
}

fun updateHeaderConfigState(
width: Int,
height: Int,
paddingStart: Int,
paddingEnd: Int,
) {
// Implementation of this method differs between Fabric & Paper!
updateState(width, height, paddingStart, paddingEnd)
}

// Implementation of this method differs between Fabric & Paper!
@UiThread
fun updateState(
private fun updateState(
width: Int,
height: Int,
paddingStart: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,13 @@ class ScreenStackHeaderConfig(

val contentInsetEnd = toolbar.currentContentInsetEnd + toolbar.paddingEnd

if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
updateHeaderConfigState(
toolbar.width,
toolbar.height,
contentInsetStart,
contentInsetEnd,
)
} else {
updatePaddings(contentInsetStart, contentInsetEnd)
}
// Note that implementation of the callee differs between architectures.
updateHeaderConfigState(
toolbar.width,
toolbar.height,
contentInsetStart,
contentInsetEnd,
)
}

override fun onLayout(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ internal class ScreenStackHeaderConfigShadowNode(
) : LayoutShadowNode() {
var paddingStart: Float = 0f
var paddingEnd: Float = 0f
var height: Float = 0f

override fun setLocalData(data: Any?) {
if (data is PaddingBundle) {
paddingStart = data.paddingStart
paddingEnd = data.paddingEnd
height = data.height

setPadding(Spacing.START, paddingStart)
setPadding(Spacing.END, paddingEnd)
setPosition(Spacing.TOP, -height)
} else {
super.setLocalData(data)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.swmansion.rnscreens.utils
// Used only on Paper together with `setLocalData` mechanism to pass
// the information on header paddings to shadow node.
data class PaddingBundle(
val height: Float,
val paddingStart: Float,
val paddingEnd: Float,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.swmansion.rnscreens

import android.content.Context
import android.view.ViewGroup
import androidx.annotation.UiThread
import com.facebook.react.bridge.ReactContext
import com.facebook.react.uimanager.StateWrapper
import com.facebook.react.uimanager.UIManagerModule
Expand All @@ -13,32 +14,40 @@ abstract class FabricEnabledHeaderConfigViewGroup(
) : ViewGroup(context) {
private var lastPaddingStart = 0
private var lastPaddingEnd = 0
private var lastHeight = 0

fun setStateWrapper(wrapper: StateWrapper?) = Unit

// Do nothing on Paper. This method is used only on Fabric.
fun updateHeaderConfigState(
width: Int,
height: Int,
paddingStart: Int,
paddingEnd: Int,
) = Unit
) {
// Implementation of this method differs between Fabric & Paper!
updateState(width, height, paddingStart, paddingEnd)
}

fun updatePaddings(
// Implementation of this method differs between Fabric & Paper!
@UiThread
private fun updateState(
width: Int,
height: Int,
paddingStart: Int,
paddingEnd: Int,
) {
// Note that on Paper we do not convert these props from px to dip. This is done internally by RN.
if (abs(lastPaddingStart - paddingStart) < DELTA && abs(lastPaddingEnd - paddingEnd) < DELTA) {
if (abs(lastPaddingStart - paddingStart) < DELTA && abs(lastPaddingEnd - paddingEnd) < DELTA && abs(lastHeight - height) < DELTA) {
return
}

lastPaddingStart = paddingStart
lastPaddingEnd = paddingEnd
lastHeight = height

val reactContext = context as? ReactContext
val uiManagerModule = reactContext?.getNativeModule(UIManagerModule::class.java)
uiManagerModule?.setViewLocalData(this.id, PaddingBundle(paddingStart.toFloat(), paddingEnd.toFloat()))
uiManagerModule?.setViewLocalData(this.id, PaddingBundle(height.toFloat(), paddingStart.toFloat(), paddingEnd.toFloat()))
}

companion object {
Expand Down
Loading