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 LifecycleEventCoroutineEffect( | |
| event: Lifecycle.Event, | |
| coroutineScope: CoroutineScope = rememberCoroutineScope(), | |
| lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, | |
| onEvent: suspend CoroutineScope.() -> Unit, | |
| ) { | |
| if (event == Lifecycle.Event.ON_DESTROY) { | |
| throw IllegalArgumentException( | |
| "LifecycleEventEffect cannot be used to " + |
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 TestComponent() { | |
| val context = LocalContext.current | |
| LifecycleEventEffect(Lifecycle.Event.ON_RESUME) { | |
| delay(1.seconds) | |
| Toast.makeText(context, "Hello, Medium", Toast.LENGTH_LONG).show() | |
| } | |
| } |
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 TestFragment : Fragment() { | |
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
| super.onViewCreated(view, savedInstanceState) | |
| viewLifecycleOwner.lifecycleScope.launch { | |
| repeatOnLifecycle(Lifecycle.State.RESUMED) { | |
| delay(1.seconds) | |
| Toast.makeText(requireContext(), "Hello, Medium", Toast.LENGTH_LONG).show() | |
| } |
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 TestFragment : Fragment() { | |
| override fun onResume() { | |
| super.onResume() | |
| requireView().postDelayed(1.seconds) { | |
| Toast.makeText(requireContext(), "Hello, Medium", Toast.LENGTH_LONG).show() | |
| } | |
| } | |
| } |
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
| fun View.postDelayed(timeout: Duration, action: Runnable) { | |
| postDelayed(action, timeout.inWholeMilliseconds) | |
| doOnDetach { removeCallbacks(action) } | |
| } |
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 TestFragment : Fragment() { | |
| override fun onResume() { | |
| super.onResume() | |
| requireView().postDelayed({ | |
| Toast.makeText(requireContext(), "Hello, Medium", Toast.LENGTH_LONG).show() | |
| }, 1_000) | |
| } | |
| } |
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 TestClass( | |
| private val context: Context, | |
| ) { | |
| private val handler = Handler(Looper.getMainLooper()) | |
| private var runnable: Runnable? = null | |
| fun onResume() { | |
| runnable = Runnable { | |
| Toast.makeText(context, "Hello, Medium", Toast.LENGTH_LONG).show() |
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 TestClass( | |
| private val context: Context, | |
| ) { | |
| fun onResume() { | |
| Handler(Looper.getMainLooper()).postDelayed({ | |
| Toast.makeText(context, "Hello, Medium", Toast.LENGTH_LONG).show() | |
| }, 1_000) | |
| } | |
| } |
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 TestClass( | |
| private val context: Context, | |
| ) { | |
| fun onResume() { | |
| thread { | |
| Thread.sleep(1_000) | |
| Toast.makeText(context, "Hello, Medium", Toast.LENGTH_LONG).show() | |
| } | |
| } |
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
| val coroutineScope = rememberCoroutineScope() | |
| val hintController = rememberHintController() | |
| // Now we can dismiss all pending hints from a hint itself | |
| val topAppBarHint = rememberHintContainer { | |
| OutlinedButton( | |
| onClick = { | |
| hintController.dismiss() | |
| } | |
| ) { Text("Hint for TopAppBar") } |
NewerOlder