• m

    Mohamed Elfiky

    2 years ago
    I have a
    LazyColumnFor
    which it's list is changed over time but when i scroll down and the list changes the
    LazyColumnFor
    does not resize i think and the white space that is left down in it is not scrollable so if no item is showing on the screen i cannot scroll up this a gist for that case: https://gist.github.com/mohamedmelfiky/28c3fbc0466b17ea96e10c8981183717
    m
    1 replies
    Copy to Clipboard
  • s

    Se7eN

    2 years ago
    Is there any way I can improve my code? I'm using compose-router
    var selectedUser: User? by remember { mutableStateOf(null) }
    
    when(currentScreen) {
        is Routing.Root.Main -> { 
            MainScreen(onChatClick = { user ->
                selectedUser = user
                // change current screen
            }
        }
        is Routing.Root.Conversation -> {
            when (val user = selectedUser) {
                null -> throw IllegalStateException("selectedUser is null")
                else -> ConversationScreen(user)
            }
        }
    }
    I don't like the way I'm handling
    selectedUser
    here
    s
    Halil Ozercan
    +1
    5 replies
    Copy to Clipboard
  • Halil Ozercan

    Halil Ozercan

    2 years ago
    I've taken SwipeToRefresh implementation from JetNews into my own project. However, I feel like there is an important bug in the implementation that comes to surface when the state of the UI directly starts in refreshing (loading) status.
    refreshingState: Boolean,
    is an argument to the SwipeToRefresh composable. It makes total sense that refreshing status is controlled by the parent. However, inner swipe state and this received state of refresh are combined together to call
    onRefresh
    callback inside the listener for swipe state change as follows:
    val state = rememberSwipeableState(refreshingState) { newValue ->
            // compare both copies of the swipe state before calling onRefresh(). This is a workaround.
            if (newValue && !refreshingState) onRefresh()
            true
        }
    However, something goes wrong in this lambda. Even if the
    refreshingState
    is changed from
    true
    to
    false
    by the parent, this lambda will keep reading it as the first time
    remember
    is called. If
    refreshingState
    was true at the start, it will remain true in the scope of this lambda until composition of
    SwipeRefreshLayout
    leaves the UI. As a workaround, I've changed
    refreshingState
    to a lambda that returns a boolean.
    Halil Ozercan
    Adam Powell
    +1
    4 replies
    Copy to Clipboard
  • s

    Se7eN

    2 years ago
    How to disable elevation overlays?
    s
    Yann Badoual
    +1
    5 replies
    Copy to Clipboard
  • m

    Mohamed Elfiky

    2 years ago
    so i have code like the below with a class represents the whole state of the screen and observing it in the root compose of that screen. is this a bad design from what i saw when i watched leland that the compose compiler is smart enough or will be to know when to recompose. second is using MutableStateFlow or mutableStateOf make any diffrence?
    enum class Sort {
        ownerName,
        taskTitle,
        size
    }
    
    sealed class UiState {
        object Loading : UiState()
        data class Success(
            val data: List<Int>,
            val sortExpanded: Boolean = false,
            val sort: Sort = Sort.ownerName,
        ) : UiState()
        object Error : UiState()
    }
    
    class UiViewModel(repo: Repo) : ViewModel() {
    
        // private val _state = MutableStateFlow<UiState>(UiState.Loading)
        // val state: StateFlow<UiState> get() = _state
        var state by mutableStateOf<UiState>(UiState.Loading)
        private set
    
        fun toggleSortDialog() {}
        ....
    }
    
    @Composable
    fun RootScreenUi() {
        val viewModel = viewModel<UiViewModel>()
        val state = viewModel.state
    
       ....
    }
    m
    John O'Reilly
    +1
    4 replies
    Copy to Clipboard
  • s

    Se7eN

    2 years ago
    TextField
    with
    adjustPan
    messes up the touch. The screen shifts up when text field is focused but when it shifts down, the touch doesn't work correctly. I think it's like the system thinks the screen is still shifted up or something like that. Is this a known issue?
    s
    1 replies
    Copy to Clipboard
  • Kyant

    Kyant

    2 years ago
    How to change shape for
    OutlinedTextField
    ?
    Kyant
    Mehdi Haghgoo
    +1
    8 replies
    Copy to Clipboard
  • Mehdi Haghgoo

    Mehdi Haghgoo

    2 years ago
    Why is it possible to write
    var cost by remember{mutableStateOf(0)}
    but not
    var (cost, setCost) by remember{mutableStateOf(0)}
    ?
    Mehdi Haghgoo
    Adam Powell
    2 replies
    Copy to Clipboard
  • Namig Tahmazli

    Namig Tahmazli

    2 years ago
    Hi All. I wonder how is it possible to get scroll x and y value for LazyColumnFor. I know that we can pass scrollState to ScrollableColumn and get scroll x value from state we passed in. But there is not such an option for LazyColumnFor.
    Namig Tahmazli
    Halil Ozercan
    +1
    4 replies
    Copy to Clipboard
  • Mehdi Haghgoo

    Mehdi Haghgoo

    2 years ago
    There is an example in Kotlin docs:
    var selectedId by savedInstanceState<String?> { null }
    Why isn't remember used here? Is it OK (or recommended) to use remember before
    savedInstanceState()
    ?
    Mehdi Haghgoo
    a
    2 replies
    Copy to Clipboard