correctly remove view

This commit is contained in:
Phillip Thelen 2023-09-14 22:29:58 +02:00
parent dd34c2ffee
commit 454d6af92c
3 changed files with 11 additions and 7 deletions

View file

@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.interactors
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.compose.ui.Modifier
@ -27,6 +28,7 @@ class ShareMountUseCase: UseCase<ShareMountUseCase.RequestValues, Unit>() {
override suspend fun run(requestValues: RequestValues) {
val mountWrapper = MountImageviewBinding.inflate(requestValues.context.layoutInflater)
mountWrapper.root.visibility = View.INVISIBLE
val width = if (mountWrapper.root.width > 0) mountWrapper.root.width else 300.dpToPx(requestValues.context)
val height = 124.dpToPx(requestValues.context)
mountWrapper.root.layout(0, 0, width, height)
@ -34,7 +36,8 @@ class ShareMountUseCase: UseCase<ShareMountUseCase.RequestValues, Unit>() {
val currentActivity =
HabiticaBaseApplication.getInstance(requestValues.context)?.currentActivity?.get()
// Add the view to the decorView so that it can be layouted
(currentActivity?.window?.decorView as? ViewGroup)?.addView(mountWrapper.root)
val containerView = (currentActivity?.window?.decorView as? ViewGroup)
containerView?.addView(mountWrapper.root)
if (currentActivity != null) {
mountWrapper.backgroundView.setContent {
HabiticaTheme {
@ -63,7 +66,7 @@ class ShareMountUseCase: UseCase<ShareMountUseCase.RequestValues, Unit>() {
((requestValues.context as? BaseActivity) ?: HabiticaBaseApplication.getInstance(
requestValues.context
)?.currentActivity?.get())?.shareContent("pet", requestValues.message, sharedImage)
currentActivity?.toolbar?.removeView(mountWrapper.root)
containerView?.removeView(mountWrapper.root)
}
// trigger layout
val m = FrameLayout.LayoutParams(width, height)

View file

@ -44,7 +44,8 @@ class SharePetUseCase: UseCase<SharePetUseCase.RequestValues, Unit>() {
petWrapper.root.visibility = View.INVISIBLE
val currentActivity =
HabiticaBaseApplication.getInstance(requestValues.context)?.currentActivity?.get()
(currentActivity?.window?.decorView as? ViewGroup)?.addView(petWrapper.root)
val containerView = (currentActivity?.window?.decorView as? ViewGroup)
containerView?.addView(petWrapper.root)
if (currentActivity != null) {
petWrapper.backgroundView.setContent {
HabiticaTheme {
@ -73,7 +74,7 @@ class SharePetUseCase: UseCase<SharePetUseCase.RequestValues, Unit>() {
((requestValues.context as? BaseActivity) ?: HabiticaBaseApplication.getInstance(
requestValues.context
)?.currentActivity?.get())?.shareContent("pet", requestValues.message, sharedImage)
currentActivity?.toolbar?.removeView(petWrapper.root)
containerView?.removeView(petWrapper.root)
}
val m = FrameLayout.LayoutParams(width, height)
petWrapper.root.layoutParams = m

View file

@ -109,9 +109,9 @@ fun MountBottomSheet(
) {
BackgroundScene()
val regularPosition = 44f
val highJump = 32f
val lowJump = 40f
val regularPosition = 40f
val highJump = 28f
val lowJump = 35f
val position by if (isAnimalFlying(mount)) {
infiniteTransition.animateFloat(
initialValue = 24f,