Improve Showkase button
This commit is contained in:
parent
42ecee8d52
commit
58acc0d80b
1 changed files with 104 additions and 101 deletions
|
|
@ -20,10 +20,8 @@ import androidx.compose.foundation.layout.size
|
|||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
|
@ -41,6 +39,8 @@ import io.element.android.x.destinations.OnBoardingScreenNavigationDestination
|
|||
import kotlinx.coroutines.runBlocking
|
||||
import timber.log.Timber
|
||||
|
||||
private const val transitionAnimationDuration = 500
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
private val viewModel: MainViewModel by viewModels()
|
||||
|
|
@ -50,25 +50,19 @@ class MainActivity : ComponentActivity() {
|
|||
// FIXME Scrolling is broken on login screens. Commenting this line fixes the issue.
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
setContent {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
ElementXTheme {
|
||||
MainScreen(viewModel = viewModel)
|
||||
}
|
||||
ShowkaseButton(
|
||||
onClick = { startActivity(Showkase.getBrowserIntent(this@MainActivity)) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ShowkaseButton(
|
||||
onClick: () -> Unit = {}
|
||||
isVisible: Boolean,
|
||||
onClick: () -> Unit,
|
||||
onCloseClicked: () -> Unit
|
||||
) {
|
||||
val showkaseButtonVisible = remember { mutableStateOf(true) }
|
||||
if (showkaseButtonVisible.value) {
|
||||
if (isVisible) {
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.padding(top = 32.dp, start = 16.dp),
|
||||
|
|
@ -79,7 +73,7 @@ private fun ShowkaseButton(
|
|||
modifier = Modifier
|
||||
.padding(start = 8.dp)
|
||||
.size(16.dp),
|
||||
onClick = { showkaseButtonVisible.value = false },
|
||||
onClick = onCloseClicked,
|
||||
) {
|
||||
Icon(imageVector = Icons.Filled.Close, contentDescription = "")
|
||||
}
|
||||
|
|
@ -98,16 +92,23 @@ private fun MainScreen(viewModel: MainViewModel) {
|
|||
}
|
||||
}
|
||||
|
||||
var isShowkaseButtonVisible by remember { mutableStateOf(BuildConfig.DEBUG) }
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) {
|
||||
MainContent(
|
||||
startRoute = startRoute
|
||||
)
|
||||
|
||||
ShowkaseButton(
|
||||
isVisible = isShowkaseButtonVisible,
|
||||
onCloseClicked = { isShowkaseButtonVisible = false },
|
||||
onClick = { startActivity(Showkase.getBrowserIntent(this@MainActivity)) }
|
||||
)
|
||||
}
|
||||
OnLifecycleEvent { _, event ->
|
||||
Timber.v("OnLifecycleEvent: $event")
|
||||
}
|
||||
}
|
||||
|
||||
private const val transitionAnimationDuration = 500
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun MainContent(startRoute: Route) {
|
||||
|
|
@ -165,3 +166,5 @@ private fun LogNavigation(navController: NavHostController) {
|
|||
fun MainContentPreview() {
|
||||
MainContent(startRoute = OnBoardingScreenNavigationDestination)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue