This file contains hidden or 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 HogeActivity { | |
val featureFlags = FeatureFlags() | |
@OptIn(AmazingFeature::class) | |
fun onClick() { | |
if (featureFlags.isAmazingFeaturesEnabled()) { | |
brokenAmazingFeatures() | |
} | |
} | |
} |
This file contains hidden or 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
@RequiresOptIn(message = "AmazingFeature should be checked") | |
@Retention(AnnotationRetention.BINARY) | |
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) | |
annotation class AmazingFeature | |
@AmazingFeature | |
fun brokenAmazingFeature() { | |
TODO("aaaaa") | |
} | |
This file contains hidden or 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 HogeActivity { | |
fun onClick() { | |
brokenAmazingFeature() // Crash when clicked!!! | |
} | |
} | |
fun brokenAmazingFeature() { | |
TODO("aaaaa") | |
} |
This file contains hidden or 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 SettingScreen( | |
settingScreenState: SettingScreenState = rememberSettingScreenState() | |
) { | |
SettingScreen( | |
scaffoldState = settingScreenState.scaffoldState, | |
isDarkModeSetting = settingScreenState.isDarkMode, | |
onDarkModeSettingChanged = { | |
settingScreenState.onDarkModeChange(it) | |
} |
This file contains hidden or 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 SettingScreen( | |
settingViewModel: SettingViewModel = viewModel(), | |
scaffoldState: ScaffoldState = rememberScaffoldState(), | |
coroutinesScope: CoroutineScope = rememberCoroutineScope(), | |
) { | |
val isDarkMode by settingViewModel.isDarkMode.collectAsState() | |
SettingScreen( | |
scaffoldState = scaffoldState, | |
isDarkModeSetting = isDarkMode, |
This file contains hidden or 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 SettingViewModel( | |
val scaffoldState: ScaffoldState | |
) : ViewModel() | |
@Composable | |
fun SettingScreen() { | |
val scaffoldState = rememberScaffoldState() | |
val settingViewModel = viewModes(factory = { SettingViewModel.Factory.create(scaffoldState) }) | |
} |
This file contains hidden or 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 SettingScreen( | |
settingViewModel: SettingViewModel = viewModel() | |
) { | |
val isDarkMode by settingViewModel.isDarkMode.collectAsState() | |
MySwitch(checked = isDarkMode, onCheckChanged = { | |
settingViewModel.onDarkModeChange(it) | |
}) | |
} |
This file contains hidden or 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
// stateful | |
@Composable | |
fun SettingScreen( | |
settingViewModel: SettingViewModel = viewModel() | |
) { | |
val isDarkMode by settingViewModel.isDarkMode.collectAsState() | |
SettingScreen(isDarkModeSetting = isDarkMode, onDarkModeSettingChanged = { | |
settingViewModel.onDarkModeChange(it) | |
}) | |
} |
This file contains hidden or 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 Screen() { | |
// I have a state in both Screen and MySwitch. | |
var checked by remember { mutableStateOf(false) } | |
Row { | |
MySwitch(initialChecked = false, onCheckChanged = {checked = it}) | |
Text( | |
text = if(checked) "on" else "false", | |
Modifier.clickable { | |
checked = !checked |
This file contains hidden or 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 Screen() { | |
// State has only on Screen | |
var checked by remember { mutableStateOf(false) } | |
Row { | |
MySwitch(checked = checked, onCheckChanged = { checked = it }) | |
Text( | |
text = if (checked) "on" else "false", | |
Modifier.clickable { | |
checked = !checked |