fix: Hacky way to fix visual glitch after dismissing dialog

Not sure why, but alpha turn to 0.0f after dialog is dismissed
This commit is contained in:
ziro 2024-01-14 10:50:05 +07:00
parent f8b760dc54
commit 2b8fd9d45e
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 23 additions and 20 deletions

View file

@ -9,6 +9,9 @@ import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.Router
import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler
import eu.kanade.tachiyomi.util.view.previousController
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
/** /**
* A controller that displays a dialog window, floating on top of its activity's window. * A controller that displays a dialog window, floating on top of its activity's window.
@ -36,14 +39,19 @@ abstract class DialogController : Controller {
*/ */
protected constructor(args: Bundle?) : super(args) protected constructor(args: Bundle?) : super(args)
protected var onCreateViewScope: CoroutineScope? = null
private set
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View {
dialog = onCreateDialog(savedViewState) onCreateViewScope = MainScope()
dialog!!.setOwnerActivity(activity!!) dialog = onCreateDialog(savedViewState).apply {
dialog!!.setOnDismissListener { dismissDialog() } setOwnerActivity(activity!!)
if (savedViewState != null) { setOnDismissListener { dismissDialog() }
val dialogState = savedViewState.getBundle(SAVED_DIALOG_STATE_TAG) if (savedViewState != null) {
if (dialogState != null) { val dialogState = savedViewState.getBundle(SAVED_DIALOG_STATE_TAG)
dialog!!.onRestoreInstanceState(dialogState) if (dialogState != null) {
onRestoreInstanceState(dialogState)
}
} }
} }
return View(activity) // stub view return View(activity) // stub view
@ -77,21 +85,10 @@ abstract class DialogController : Controller {
* @param router The router on which the transaction will be applied * @param router The router on which the transaction will be applied
*/ */
open fun showDialog(router: Router) { open fun showDialog(router: Router) {
showDialog(router, null)
}
/**
* Display the dialog, create a transaction and pushing the controller.
* @param router The router on which the transaction will be applied
* @param tag The tag for this controller
*/
fun showDialog(router: Router, tag: String?) {
dismissed = false dismissed = false
router.pushController( router.pushController(
RouterTransaction.with(this) RouterTransaction.with(this)
.pushChangeHandler(SimpleSwapChangeHandler(false)) .pushChangeHandler(SimpleSwapChangeHandler(false)),
.popChangeHandler(SimpleSwapChangeHandler(false))
.tag(tag),
) )
} }
@ -102,7 +99,13 @@ abstract class DialogController : Controller {
if (dismissed) { if (dismissed) {
return return
} }
val prev = this.previousController
router.popController(this) router.popController(this)
// FIXME: This is a hack so that previous controller stays visible
prev?.let {
if (it !is BaseController) return@let
it.view?.alpha = 1.0f
}
dismissed = true dismissed = true
} }

View file

@ -15,7 +15,7 @@ coil-svg = { module = "io.coil-kt:coil-svg", version.ref = "coil" }
coil-gif = { module = "io.coil-kt:coil-gif", version.ref = "coil" } coil-gif = { module = "io.coil-kt:coil-gif", version.ref = "coil" }
coil = { module = "io.coil-kt:coil", version.ref = "coil" } coil = { module = "io.coil-kt:coil", version.ref = "coil" }
compose-theme-adapter3 = { module = "com.google.accompanist:accompanist-themeadapter-material3", version = "0.33.2-alpha" } compose-theme-adapter3 = { module = "com.google.accompanist:accompanist-themeadapter-material3", version = "0.33.2-alpha" }
conductor = { module = "com.bluelinelabs:conductor", version = "4.0.0-preview-3" } conductor = { module = "com.bluelinelabs:conductor", version = "4.0.0-preview-4" }
conductor-support-preference = { module = "com.github.tachiyomiorg:conductor-support-preference", version = "3.0.0" } conductor-support-preference = { module = "com.github.tachiyomiorg:conductor-support-preference", version = "3.0.0" }
conscrypt = { module = "org.conscrypt:conscrypt-android", version = "2.5.2" } conscrypt = { module = "org.conscrypt:conscrypt-android", version = "2.5.2" }
directionalviewpager = { module = "com.github.tachiyomiorg:DirectionalViewPager", version = "1.0.0" } directionalviewpager = { module = "com.github.tachiyomiorg:DirectionalViewPager", version = "1.0.0" }