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
@Stable | |
interface MutableState<T> : State<T> { | |
override var value: T | |
operator fun component1(): T | |
operator fun component2(): (T) -> Unit | |
} |
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 main() { | |
val list = listOf(1, 2, 3, 4, 5, 6) | |
list.headRecursion { print(it) } | |
} | |
fun <T> List<T>.headRecursion(index: Int = lastIndex, next: (item: T) -> Unit) { | |
if (index >= 0) { | |
headRecursion(index - 1, next) | |
next.invoke(get(index)) | |
} |
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
sealed class DownloadManagerStatus { | |
sealed class DownloadStatus : DownloadManagerStatus() { | |
sealed class StatusPaused : DownloadStatus() { | |
object QueuedForWifi : StatusPaused() | |
object WaitingForNetwork : StatusPaused() | |
object WaitingToRetry : StatusPaused() | |
object Unknown : StatusPaused() | |
} |
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
@ExperimentalComposeUiApi | |
@Composable | |
fun OtpBugView() { | |
val (editValue, setEditValue) = remember { mutableStateOf("") } | |
val otpLength = remember { 4 } | |
val focusRequester = remember { FocusRequester() } | |
val keyboard = LocalSoftwareKeyboardController.current | |
// hidden TextField for controlling OTP Cells UI |
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 OtpCell( | |
modifier: Modifier, | |
value: String, | |
isCursorVisible: Boolean = false | |
) { | |
val scope = rememberCoroutineScope() | |
val (cursorSymbol, setCursorSymbol) = remember { mutableStateOf("") |
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 CaptureBitmap( | |
content: @Composable ()->Unit | |
) : () -> Bitmap // <---- this will return a callback which returns a bitmap | |
{ | |
val composeView = ComposeView(...) | |
//callback that convert view to bitmap | |
fun captureBitmap() = composeView.drawToBitmap() |
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 CaptureBitmap( | |
content: @Composable ()->Unit // <--- we use callback as parameter | |
){ | |
val composeView = ComposeView(...) | |
AndroidView( | |
factory = { | |
composeView.apply { |
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 CaptureBitmap(...){ | |
// we will use compose view as target to get bitmap | |
val composeView = ComposeView(...) | |
// put compose native view to compose ui using AndroidView | |
AndroidView( | |
factory = { | |
composeView.apply { |
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
// Native View which accepts Composable as its View Content | |
ComposeView(context).apply { | |
setContent { | |
// composable goes here! | |
} | |
} |
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
Coloumn { | |
val snapShot = CaptureBitmap { | |
Button( | |
onClick = {}, | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(24.dp) | |
.height(55.dp), | |
) { | |
Text(text = "Capture my image") |