Skip to content

Commit

Permalink
调整Transform,修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ErolC committed Jun 21, 2024
1 parent 70ea5df commit 6948878
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ actual class LifecycleOwnerDelegate private constructor(
}

companion object {
fun create(
internal fun create(
viewModelStoreProvider: MRouterViewModelStoreProvider?,
hostLifecycleState: Lifecycle.State = Lifecycle.State.CREATED,
immutableArgs: Bundle?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PageEntry internal constructor(

private val pageCache = PageCache()
internal var callBack: ResultCallBack? = null
private lateinit var original:Transform


init {
Expand Down Expand Up @@ -92,6 +93,11 @@ class PageEntry internal constructor(
// 管理当前页面的路由器
private val pageRouter: PageRouter get() = scope.router.parentRouter

internal fun setTransform(transform: Transform){
original = transform
this.transform.value = original
}

@Composable
override fun Content(modifier: Modifier) {
scope.windowId = LocalWindowScope.current.id
Expand Down Expand Up @@ -226,6 +232,7 @@ class PageEntry internal constructor(
*/
private fun updatePrevTransform(prev: PageEntry): TransformState {
if (prev.isUpdateTransform) return StopState
transform.value = original
prev.transform.value = prev.transform.value.copy(exit = transform.value.exit)
prev.transform.value.wrap.updatePauseModifier(transform.value.wrap.pauseModifierPost)
prev.isUpdateTransform = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.erolc.mrouter.model.PanelOptions
import com.erolc.mrouter.model.Route
import com.erolc.mrouter.platform.isMobile
import com.erolc.mrouter.model.WindowOptions
import com.erolc.mrouter.platform.isAndroid
import com.erolc.mrouter.platform.isIos
import com.erolc.mrouter.route.transform.*
import com.erolc.mrouter.window.WindowOptionsBuilder
Expand All @@ -28,7 +29,7 @@ class RouteBuilder(currentWindowId: String = Constants.DEFAULT_WINDOW) {

var flag: RouteFlag = NormalFlag

var transform: Transform = normal(if (isMobile) GestureModel.Both else GestureModel.None)
var transform: Transform = normal(if (isAndroid) GestureModel.Both else if(isIos) GestureModel.Local else GestureModel.None)

private var panelOptions: PanelOptions? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal fun createPageEntry(
createLifecycleOwnerDelegate(viewModelStoreProvider, hostLifecycleState, route.args)
).apply {
flag = if (isReplace) route.flag + ReplaceFlag else route.flag
transform.value = route.transform
setTransform(route.transform)
callBack = route.callback
scope.run {
this.router = router
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import com.erolc.mrouter.platform.iosHasNotch
import com.erolc.mrouter.platform.safeAreaInsetsTop

/**
* 类ios的Modal手势实现,在页面route时设置[modal]即可使用
*/
class ModalTransformWrap(private val proportion: Float, gestureModel: GestureModel) :
TransformWrap(gestureModel) {
private val prevCorner = if (iosHasNotch) safeAreaInsetsTop() else 0f

@Composable
override fun Wrap(modifier: Modifier) {
Expand All @@ -40,7 +36,7 @@ class ModalTransformWrap(private val proportion: Float, gestureModel: GestureMod
override fun prevPageModifier(): Modifier {
val transform = rememberTransformState()
val corner by transform.animateDp {
it.between(prevCorner.dp, prevCorner.dp, pause = 10.dp)
it.between(corner, corner, pause = 10.dp)
}
return Modifier.clip(RoundedCornerShape(corner))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.erolc.mrouter.platform.Windows
import com.erolc.mrouter.platform.getPlatform
import com.erolc.mrouter.platform.iosHasNotch
import com.erolc.mrouter.platform.isIos
import com.erolc.mrouter.platform.safeAreaInsetsTop
import com.erolc.mrouter.route.transform.share.NormalShareTransformWrap
import com.erolc.mrouter.utils.*
import kotlin.math.roundToInt
Expand All @@ -32,6 +33,9 @@ private val modalScale: Float =
private val modalProportion: Float =
if (iosHasNotch) Constants.IOS_NOTCH_MODAL_PROPORTION else if (isIos || getPlatform() == Mac) Constants.IOS_MODAL_PROPORTION else if (getPlatform() == Windows) 0.96f else 0.956f

internal val corner = (if (iosHasNotch) safeAreaInsetsTop() -5 else 0f).dp

private val normalTransformWrap = NormalTransformWrap(if (isIos) GestureModel.Local else GestureModel.None)
/**
* modal的页面过渡动画,类ios的modal效果
*/
Expand Down Expand Up @@ -362,7 +366,7 @@ class TransformBuilder {
*/
var popExit: ExitTransition = ExitTransition.None

var wrap: TransformWrap = NormalTransformWrap(GestureModel.None)
var wrap: TransformWrap = normalTransformWrap
internal fun build(): Transform {
return Transform(enter, popExit, exit, wrap)
}
Expand All @@ -388,7 +392,7 @@ data class Transform internal constructor(
internal val enter: EnterTransition = EnterTransition.None,
private val _popExit: ExitTransition = ExitTransition.None,
internal val exit: ExitTransition = slideOutHorizontally { 0 },
internal val wrap: TransformWrap = NormalTransformWrap(GestureModel.None)
internal val wrap: TransformWrap = normalTransformWrap
) {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ actual class LifecycleOwnerDelegate private constructor(
}

companion object {
fun create(
internal fun create(
viewModelStoreProvider: MRouterViewModelStoreProvider?,
hostLifecycleState: Lifecycle.State = Lifecycle.State.CREATED,
immutableArgs: Bundle?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ actual class LifecycleOwnerDelegate private constructor(
}

companion object {
fun create(
internal fun create(
viewModelStoreProvider: MRouterViewModelStoreProvider?,
hostLifecycleState: Lifecycle.State = Lifecycle.State.CREATED,
immutableArgs: Bundle?,
Expand Down

0 comments on commit 6948878

Please sign in to comment.