Daniel
06/09/2021, 7:18 PMensureFineLocation
that handles the whole permission flow and then passing a reference to the function down through the composables.
This seems like it will scale pretty badly though, both in that the activity has a lot of unrelated methods and I've got to pass a lot of free functions.
Also, since registerForActivityResult
is global state I'm not sure the right way to handle repeated calls. I'm currently using a MutableState like so
private val fineLocationStatus = MutableState<Boolean?>(null)
private val requestFineLocationLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
fineLocationStatus.value = isGranted
}
private fun ensureFineLocation(): Boolean {
val initialCached = fineLocationStatus.value
if (initialCached != null) {
if (!initialCached) showFineLocationMissingError()
return initialCached
}
val permission = Manifest.permission.ACCESS_FINE_LOCATION
if (checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) return true
if (shouldShowRequestPermissionRationale(permission)) {
if (!fineLocationRationalePrompt()) {
fineLocationDeniedMsg()
return false
}
}
requestFineLocationLauncher.launch(permission)
val cached = fineLocationStatus.filterNotNull().first()
if (!cached) fineLocationDeniedMsg()
return cached
}
This is a little racy if there are multiple calls before a value is cached. I'm also not sure the value should be cached, so I considered clearing the mutable state before returning. Then I think I'd need to protect ensureFineLocation
with a mutex, though.
I feel like there has to be a better solution. Is there a reason why registerForActivityResult
uses a global callback instead of giving each request a different requestCode so that you can have a suspend fun like launcher.awaitResult
?rook
06/09/2021, 7:51 PM@Composable
functions from a compiled aar? Specifically, ensuring that the consuming application has all the necessary compose dependencies and configurations to handle its presence. I want to compose the UI with Compose and then expose it via my API either as a Composable method or as a traditional view component. I’m having trouble finding documentation on this.Daniel Rampelt
06/09/2021, 8:35 PM1.0.0-beta08
into an existing application with Kotlin 1.5.10
and AGP 7.1.0-alpha02
. I'm getting the following error and I'm not sure how to further debug it. More details in :thread-please:
java.lang.NoSuchMethodError: No static method setContent$default(...)
eschrag
06/09/2021, 8:38 PMChristopher Elías
06/10/2021, 4:06 AM1.0.0-beta08
but Im not able to use modifiers... every extension is just red on the IDE does someone is having the same issue?Philip S
06/10/2021, 5:55 AMZach Klippenstein (he/him) [MOD]
06/10/2021, 6:10 AMuseUnmergedTree=true
to the node matcher, which seems unintuitive.frankelot
06/10/2021, 8:30 AMMutableState<T>
and MutableStateFlow<T>
, when should I use each?louiscad
06/10/2021, 9:39 AMAlex Bieliaiev
06/10/2021, 9:58 AMnestedScroll
thing. So I have a ModalBottomSheetLayout
and a vertically scrollable column within that bottom sheet. ModalBottomSheetLayout
participates in the nested scrolling (please see PreUpPostDownNestedScrollConnection
). As far, as I understand the logic, ModalBottomSheetLayout
consumes entire scroll delta through the onPreScroll
, so the actual scroll target (the child column) doesn't receive any delta at all. This results into the bottom sheet being dragged vertically instead of the column being scrolled. Any suggestions?Akram Bensalem
06/10/2021, 10:31 AMmarios proto
06/10/2021, 12:02 PMStateFlow
of different states. e.g.
sealed class MyState{
object Loading…
class ShowList(val list:List<String> ) …
class Itemselected( val item:String)...
class Error( val message:String )…
}
and then on the content I want to display something like
@Composable
fun MyPage(viewModel: MyViewModel) {
val state: MyState by viewModel.getStateFlow()
.collectAsState(initial = MyState.Loading)
Column {
Header("Home")
PageBody(state)
}
}
@Composable
fun PageBody(state: ServiceHubHomeState) {
when (state) {
MyState.Loading -> Header("Loading")
is MyState.ShowList ->
ListHub(serviceItems = state.list)
is MyState.ItemSelected -> { // do something else
}
}
}
So now, when I use .collectAsState, everything works all-right, BUT,
when I have already published a value of Showlist, and a list is rendered,
if a new state comes, e.g ItemSelected of course the list is cleaned up.
My question is, how do I keep the already rendered list between the next state transitions?
I am sure I have to keep the state somewhere but cannot see it 😞Peter Mandeljc
06/10/2021, 12:15 PMBottomDrawer
?
@Composable
fun Screen() = Scaffold {
BottomDrawer(
drawerContent = { DrawerContent() },
content = { ScreenContent() },
)
}
dimsuz
06/10/2021, 12:37 PMRodri Represa
06/10/2021, 2:25 PMvar test = mutableStateOf<List<Int>>(emptyList())
/**
I add some values to test {0,1,2}
**/
test = emptyList()
Slackbot
06/10/2021, 2:48 PMSuperblazer
06/10/2021, 2:53 PMJoey
06/10/2021, 3:03 PMdimsuz
06/10/2021, 3:31 PMImage
which has fillMaxSize()
and contentScale = FillBounds
, but the painter is still drawn in center of the image, why is that? It seems that contentScale is completely ignored (example in the thread)tylerwilson
06/10/2021, 4:44 PMdimsuz
06/10/2021, 5:14 PMLazyListState
has animateBy
which accepts an AnimationSpec
and it also has animateScrollToItem
which doesn't accept AnimationSpec
and hardcodes it to spring()
. Is this asymmetry on purpose? Or can I request this feature?Ryan Simon
06/10/2021, 6:43 PMLazyColumn
and I'm wondering if it's intended behavior. I am observing a LiveData
as State
and whenever it gets updated, the UI should update as expected.
The weird thing though is that my LazyColumn
won't update properly unless I use the key
property in the items
extension within the LazyListScope
. Sample code in the threadZach Klippenstein (he/him) [MOD]
06/10/2021, 7:50 PMcontentDescription
doesn’t get merged up? More details in the thread on the original message.Daniel
06/10/2021, 8:32 PMshouldShowRequestPermissionRationale()
. What are people doing?Ravi
06/10/2021, 8:38 PMandroidx.paging:paging-compose:1.0.0-alpha10
Christopher Elías
06/10/2021, 8:49 PMUnsupportedException
, does anybody has trying to do the same and actually succeed?
@Composable
fun LinearTransactionsChart(
modifier: Modifier = Modifier,
transactionsPerSecond: TransactionsPerSecond,
defaultDispatcher: CoroutineDispatcher
) {
if (transactionsPerSecond.transactions.isEmpty()) return
val composableScope = rememberCoroutineScope()
Canvas(modifier = modifier) {
composableScope.launch(Dispatchers.Main) {
emitTransactions(
defaultDispatcher = defaultDispatcher,
maxTransaction = transactionsPerSecond.maxTransaction,
transactions = transactionsPerSecond.transactions,
canvasWidth = size.width,
canvasHeight = size.height
) { start, end ->
drawLine(
start = start,
end = end,
color = Color(0xFFFFFFFF)
)
}
}
}
}
// The list can have like 1K ~ 2K items...
suspend fun emitTransactions(
defaultDispatcher: CoroutineDispatcher,
maxTransaction: Double,
transactions: List<TransactionRate>,
canvasWidth: Float,
canvasHeight: Float,
dots: (start: Offset, end: Offset) -> Unit
) {
// ... Do some heavy computation for creating the start and end Offset...
withContext(defaultDispatcher) {
transactions.forEachIndexed { index, transactionRate ->
dots(Offset(x, y), Offset(x, y))
}
}
}
Barry Fawthrop
06/10/2021, 9:21 PMbuildscript {
ext {
compose_version = "1.0.0-beta08"
kotlin_version = "1.5.10"
}
Not sure where it's getting beta07 from I can't find it anywhere in the projectnglauber
06/11/2021, 12:18 AMColton Idle
06/11/2021, 12:56 AM@Composeable fun MyEmailInputField() { ... }
@Composeable fun MyPhoneInputField() { ... }
@Composeable fun MyPasswordInputField() { ... }
Would you have:
1️⃣ the validation/restriction of chars is built into the Composable
2️⃣ the validation/restriction of chars is built into your "ViewModel"Slackbot
06/11/2021, 8:46 AMSlackbot
06/11/2021, 8:46 AMAlbert Chang
06/11/2021, 9:24 AMcollectAsState()
on a Flow
also brings out this problem.streetsofboston
06/11/2021, 11:42 AMsuspend fun doSomethingScary1() {
if (!canDoSomethingScary.first()) return
// do something scary
}
instead of using stateIn
?Colton Idle
06/11/2021, 12:11 PMKirill Vasilenko
06/11/2021, 1:30 PMstreetsofboston
06/11/2021, 1:31 PMdoSomethingScary1
is suspend as well.Kirill Vasilenko
06/11/2021, 1:32 PM