Skip to content

Commit

Permalink
WeakReference wrap context
Browse files Browse the repository at this point in the history
  • Loading branch information
teble committed Feb 12, 2024
1 parent 4c2dd6e commit 474d46b
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import me.teble.xposed.autodaily.ui.XAutoDailyApp
import me.teble.xposed.autodaily.utils.navigationBarMode
import me.teble.xposed.autodaily.utils.setNavigationBarTranslation
import me.teble.xposed.autodaily.utils.setStatusBarTranslation
import java.lang.ref.WeakReference

class ModuleActivity : BaseActivity(), CoroutineScope by MainScope() {

companion object {
lateinit var composeViewContext: Context
var composeViewContext = WeakReference<Context>(null)
}

override fun onDestroy() {
Expand All @@ -55,7 +56,7 @@ class ModuleActivity : BaseActivity(), CoroutineScope by MainScope() {
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
composeViewContext = context
composeViewContext = WeakReference(context)
this.setContent {
MaterialTheme(colors = colors()) {
Scaffold {
Expand Down Expand Up @@ -83,7 +84,9 @@ class ModuleActivity : BaseActivity(), CoroutineScope by MainScope() {

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
injectRes(composeViewContext.resources)
composeViewContext.get()?.let {
injectRes(it.resources)
}
}
}

Expand Down

0 comments on commit 474d46b

Please sign in to comment.