-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modal antes de iniciar benchmarking e conversa
- Loading branch information
1 parent
8df4042
commit 029de51
Showing
4 changed files
with
182 additions
and
71 deletions.
There are no files selected for viewing
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
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
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
54 changes: 54 additions & 0 deletions
54
android/MLCChat/app/src/main/java/ai/mlc/mlcchat/hooks/useModal.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ai.mlc.mlcchat.hooks | ||
|
||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
|
||
data class ModalActions( | ||
val show: () -> Unit, | ||
val hide: () -> Unit | ||
) | ||
|
||
@Composable | ||
fun useModal( | ||
title: String, | ||
text: String, | ||
onConfirm: () -> Unit, | ||
confirmLabel: String, | ||
dismissLabel: String = "Cancel" | ||
): ModalActions { | ||
|
||
var visible by remember { mutableStateOf(false) } | ||
|
||
fun show() { | ||
visible = true | ||
} | ||
|
||
fun hide() { | ||
visible = false | ||
} | ||
|
||
if(visible) { | ||
AlertDialog( | ||
title = { Text(text = title) }, | ||
text = { Text(text = text) }, | ||
onDismissRequest = ::hide, | ||
confirmButton = { | ||
TextButton(onClick = { onConfirm(); hide() }) { Text(confirmLabel) } | ||
}, | ||
dismissButton = { | ||
TextButton(onClick = ::hide) { Text(dismissLabel) } | ||
} | ||
) | ||
} | ||
|
||
return ModalActions( | ||
show = ::show, | ||
hide = ::hide | ||
) | ||
} |