voben
11/18/2021, 12:19 AMColton Idle
11/18/2021, 3:38 AMAndroid75
11/18/2021, 3:47 AMelye
11/18/2021, 5:10 AM@Composable
override fun Content() {
val elapsedTime= measureTimeMillis {
MyDeepHierarchyJetpackComposeDrawing()
}
Log.d("Tracking", "Time used $elapsedTime")
}
Thanks!Zoltan Demant
11/18/2021, 9:13 AMScreen
and I can guarantee that its immutable, would it recompose fewer times/perform better if I wrapped it in a ScreenWrapper
marked with @Immutable
? I cant mark the actual screen, but I can use a value/inline class for the wrapper.AmrJyniat
11/18/2021, 11:25 AMrememberSaveable
with FocusRequester
? it gives me a crash.loloof64
11/18/2021, 12:24 PMcoroutineScope.launch {
in order to start a coroutine in my code. But is there a variant of launch
which runs the coroutine for a given amount of time, instead of infinitely ? Because otherwise, I'm afraid my code, which is a bit a kind of spaghetti as now, will be worse.miqbaldc
11/18/2021, 3:27 PMFatal Exception: java.lang.IllegalStateException: Compose assumes that all pointer ids in MotionEvents are first provided alongside ACTION_DOWN or ACTION_POINTER_DOWN. This appears not to have been the case
Vlad Gorbunov
11/18/2021, 7:39 PMTextField
?
For EditText
i’ve used this..
ViewCompat.setOnReceiveContentListener(chatInput.textInput, arrayOf("image/*", "video/*"))
is there an option to not insert custom AndroidView
? 🤞jeff
11/18/2021, 9:07 PMColumn
with 2 children. I want the second child's height to be exactly 100.dp, and the first child's height to take up the remainder. What's the easiest way to accomplish that? Putting Modifier.fillMaxHeight
on the first child doesn't seem to cut itChris Fillmore
11/18/2021, 10:29 PMflowWithLifecycle
, and I’m wondering if it’s wise (some code in thread)Bradleycorn
11/19/2021, 1:42 AMClickableText
(with an annotated string), and I only handle clicks on a certain portion of the string, like this:
onClick = { pos ->
if (pos in linkStart..linkEnd) {
onLoginClicked()
}
}
How can I test this?
I need a way in the test to click on a certain position (string index) in the text.
performClick()
doesn’t take any parameters that I could use to click at a certain position.
Using performTouchInput()
let’s me move by a number of pixels, but I’m not sure how that helps since I need to click based on string position.Slackbot
11/19/2021, 1:48 AMColton Idle
11/19/2021, 5:46 AMrattleshirt
11/19/2021, 8:18 AM@Preview
? For example rememberPermissionState
has calls to Context
or when remembering some specific Android API like MediaPlayer. Should those be provided through a CompositionLocalProvider
at the root level or is there some other way to “fake” these?Abhinav Sharma
11/19/2021, 9:13 AMHorizontalTrayUi()
and TrayItemUi()
Its easy to test TrayItemUi()
in isolation by mocking TrayItemViewModel
and its exposed state flows, but whats the recommended way to test HorizontalTrayUi()
as it calls TrayItemUi()
which then tries to create a viewModel using Hilt
Here’s the structure
@Composable
fun HorizontalTrayUi(
trayModel: TrayModle,
viewModel: TrayViewModel = viewModel()
) {
Text(...) // title of the tray
LazyRow(..){
item -> {
TrayItemUi(item)
}
}
}
@Composable
fun TrayItemUi(
item: TrayItemModel,
viewModel: TrayItemViewModel = viewModel()
) {
......
}
@Pedro Gomeztylerwilson
11/19/2021, 1:58 PMdimsuz
11/19/2021, 3:01 PMTest
composable in the snippet is not recomposed on state change, it's only called once. This seems to happen only if this Box is placed inside a sheetContent
of BottomSheetScaffold
:
Box {
var enable by remember { mutableStateOf(true) }
println("enable out=$enable")
Test(enable = enable)
Button(onClick = { enable = !enable })
}
@Composable
fun Test(enable: Boolean) {
println("enable in=$enable")
Text(text = enable.toString())
}
Jérémy CROS
11/19/2021, 4:51 PMSurface
element?
It’s an app for blind people and we have another mean of describing the content of the view with talkback
Something like importantForAccessibility="noHideDescendants"
Bradleycorn
11/19/2021, 7:40 PMTextField( value = myText,
onValueChanged = { new -> myText = new },
modifier = Modifier.testTag("MyInput"))
And I’m trying to set some text in the text field in a test:
composeTestRule.onNodeWithTag("MyInput").performTextInput("Test")
My test fails, and I get the error:
No input session started. Missing a focus?
What am I doing wrong here? Doing some digging into the testing source and debugging the nodes, it looks like the TextField
node doesn’t get focused for some reason. I tried adding a performClick()
before setting the text, but that didn’t help either. The node still has focused = false
… What am I missing?AmrJyniat
11/20/2021, 6:53 AMScaffoldState
work with CompositionLocalProvider
to control the drawer open/close from anywhere in my fragment?Adib Faramarzi
11/20/2021, 10:35 AMAnimatedVisibility
? (like onFinishedListener
)Mehdi Haghgoo
11/20/2021, 8:47 PMursus
11/20/2021, 9:25 PM() -> @Composable Unit
lamdas? Qualifieres everywhere? Or maybe some typesafe object based Screen? is that a bad idea? (since it doesnt really compose if needed, same way fragments sort of did)skwalking
11/21/2021, 7:05 AM@Composable
fun GetContentExample() {
val context = LocalContext.current
var directoryUri by remember { mutableStateOf<Uri?>(null) }
//val imageUri = mutableListOf<Uri?>()
//val cR = context.contentResolver
val launcher =
rememberLauncherForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri: Uri? ->
directoryUri = uri
}
Column(modifier = Modifier.fillMaxSize()) {
Button(onClick = { launcher.launch(directoryUri) }) {
Text(text = "Load Image")
}
val documentFile = directoryUri?.let { DocumentFile.fromTreeUri(context, it) }
val files = documentFile?.listFiles()
val pathList = mutableListOf<DocumentFile>()
files?.forEach { file ->
if (file.type == "image/jpeg") {
pathList.add(file)
}
}
LazyColumn(modifier = Modifier.fillMaxSize()) {
items(items = pathList) { path ->
Text(text = path.uri.toString())
Image(
painter = rememberImagePainter(path.uri),
contentDescription = "My Image"
)
Spacer(modifier = Modifier.height(20.dp))
}
}
}
}
Help Text appearing but not the images.
Here I'm first taking access to pictures folder then wanna show it on LazyColumn...
It'll be good if you provide source I can read to know how to display, copy images from one folder to another 🙂dimsuz
11/21/2021, 4:53 PMK Merle
11/22/2021, 6:01 AMNapa Ram
11/22/2021, 6:17 AMziv kesten
11/22/2021, 9:25 AMmodifier = Modifier
.padding(horizontal = 26.dp)
.background(colorResource(R.color.lemonade_cloud), shape = RoundedCornerShape(7.dp))
.fillMaxWidth()
.wrapContentHeight()
.clickable(onClick = {
onLogoutClicked.invoke()
}, indication = rememberRipple(bounded = true),
interactionSource = remember { MutableInteractionSource() })
.padding(vertical = 15.dp, horizontal = 20.dp),
Mehdi Haghgoo
11/22/2021, 10:24 AMMehdi Haghgoo
11/22/2021, 10:24 AMnitrog42
11/22/2021, 10:35 AMMehdi Haghgoo
11/22/2021, 10:40 AMnitrog42
11/22/2021, 10:44 AMMehdi Haghgoo
11/22/2021, 10:50 AMclass MainViewModel : ViewModel() {
// TODO: Implement the ViewModel
private val _currentMessage: MutableLiveData<String> = MutableLiveData("")
private val _messages: MutableLiveData<MutableList<String>> = MutableLiveData()
val messages: LiveData<MutableList<String>> = _messages
val currentMessage: LiveData<String> = _currentMessage
fun setCurrentMessage(message:String){
_currentMessage.value = message
}
fun onAddMessage(message: String){
// val temp = mutableListOf(message).apply{
// _messages.value?.let { addAll(it) }
// }
// _messages.value = temp
_messages.value?.add(message)
Log.d("MainViewModel", "onAddMessage: New message added: $message. Total: ${_messages.value?.size}")
}
}
Code that uses it:
Column{
Log.d("MainFragment", "onCreateView: number of messages: ${messages?.size}")
messages?.forEach { msg -> Text(msg, Modifier.padding(8.dp)) }
}
nitrog42
11/22/2021, 10:53 AMprivate val _messages: MutableLiveData<MutableList<String>> = MutableLiveData()
-> _messages is empty, you need to either use MutableLiveData(mutableList()) or pass the list (as in your commented code)val message = mutableStateListOf()
Mehdi Haghgoo
11/22/2021, 11:08 AMZach Klippenstein (he/him) [MOD]
11/22/2021, 3:57 PMColton Idle
11/22/2021, 6:17 PMA mutable list inside a state holder (a MutableState, StateFlow, LiveData, etc) is always a smell.Makes sense.
Either use an immutable listok
or that mutableStateListOfI would assume mutableStateListOf is the thing I should reach for first typically?
Zach Klippenstein (he/him) [MOD]
11/22/2021, 6:40 PMColton Idle
11/22/2021, 6:50 PMZach Klippenstein (he/him) [MOD]
11/24/2021, 3:43 PM