This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sourceSets { | |
commonMain.dependencies { | |
implementation("org.jetbrains.compose.ui:ui") | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.compose.ui.ExperimentalComposeUiApi | |
import androidx.compose.ui.platform.LocalDensity | |
import androidx.compose.ui.platform.LocalWindowInfo | |
@OptIn(ExperimentalComposeUiApi::class) | |
@Composable | |
actual fun rememberScreenSizeInfo(): ScreenSizeInfo { | |
val density = LocalDensity.current | |
val config = LocalWindowInfo.current.containerSize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
expect fun rememberScreenSizeInfo(): ScreenSizeInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun App() { | |
val screenSizeInfo = rememberScreenSizeInfo() | |
val uiType = screenSizeInfo.getUiType() | |
MaterialTheme { | |
when (uiType) { | |
UiType.COMPACT -> CompactUi() | |
UiType.MEDIUM -> MediumUi() | |
UiType.EXPANDED -> ExpandedUi() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun ScreenSizeInfo.getUiType(): UiType { | |
return when (widthDp){ | |
in 0.dp..600.dp -> UiType.COMPACT | |
in 600.dp..840.dp -> UiType.MEDIUM | |
else -> UiType.EXPANDED | |
} | |
} | |
enum class UiType { | |
COMPACT, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun rememberScreenSizeInfo(): ScreenSizeInfo { | |
val config = LocalConfiguration.current | |
return remember(config) { | |
ScreenSizeInfo( | |
heightDp = config.screenHeightDp.dp, | |
widthDp = config.screenWidthDp.dp | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SettingsOverviewScreen : Screen { | |
@Composable | |
override fun Content() { | |
val navigator = LocalNavigator.current | |
SettingsOverview(onNavigate = { | |
navigator?.push(SettingsDetailScreen()) | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SettingsTab : Tab { | |
override val options: TabOptions | |
@Composable | |
get() { | |
val title = stringResource(R.string.settings_tab) | |
val icon = rememberVectorPainter(Icons.Default.Settings) | |
return remember { | |
TabOptions( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun RowScope.TabNavigationItem(tab: Tab) { | |
val tabNavigator = LocalTabNavigator.current | |
BottomNavigationItem( | |
selected = tabNavigator.current == tab, | |
onClick = { tabNavigator.current = tab }, | |
label = { | |
Text(text = tab.options.title) | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContent { | |
MainContent() | |
} | |
} | |
} | |
@Composable |
NewerOlder