Skip to content

Commit

Permalink
Add generic Compose fragment.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal authored and nicholas-signal committed Feb 2, 2023
1 parent fb07e89 commit 63a1535
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.thoughtcrime.securesms.compose

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.ViewCompositionStrategy
import org.signal.core.ui.theme.SignalTheme
import org.thoughtcrime.securesms.LoggingFragment
import org.thoughtcrime.securesms.util.DynamicTheme

/**
* Generic ComposeFragment which can be subclassed to build UI with compose.
*/
abstract class ComposeFragment : LoggingFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return ComposeView(requireContext()).apply {
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
setContent {
SignalTheme(
isDarkMode = DynamicTheme.isDarkTheme(LocalContext.current)
) {
SheetContent()
}
}
}
}

@Composable
abstract fun SheetContent()
}

0 comments on commit 63a1535

Please sign in to comment.