```viewModel.notes.observeInLifecycleScope { notes...
# android
o
Copy code
viewModel.notes.observeInLifecycleScope { notes ->
            viewBinding.informationTextInput.text = notes
            // Fix for mysterious bug when the family notes textview doesnt update when navigated from home screen.
            lifecycleScope.launch {
                viewBinding.informationTextInput.isVisible = false
                viewBinding.informationTextInput.isVisible = true
                repeat(10) {
                    delay(100)
                    viewBinding.informationTextInput.isVisible = false
                    viewBinding.informationTextInput.isVisible = true
                }
            }
        }
There is this mysterious bug where screen A works fine when navigated from screen B(screen B -> screen A) . But when navigated from screen C -> screen A, there is this small chance the textview showing weird, empty content. The code under the comment hilariously fixes that issue... but still have no clue why 😂
l
Are screens fragments or activity or in both cases? Do you have github link for this?
o
It is a single activity app, so all screens are fragments, inside the same activity. The app uses Android Navigation Component
I don't have a GitHub link for this, sorry
Maybe info worth adding: screen A is a constraintlayout inside a Coordinatorlayout
Or better, its like this: CoordinatorLayout -> NestedScrollView -> ConstraintLayout
i
What is
observeInLifecycleScope
doing? Make sure it is using the
viewLifecycleOwner
and not the Fragment itself for getting the
lifecycleScope
o
Copy code
// BaseFragment.kt
protected fun <T> LiveData<T>.observeInLifecycleScope(observer: (T) -> Unit) {
        observe(viewLifecycleOwner, observer)
    }
Ok, completely unrelated to the previous code, but this just happens on a different screen, it looks like it might not be navigation related at all. As you can see in the layout inspector, the start_date text = "do 22 okt. 2020", but the screen is just showing the first letter: "d". Might this be a Constraintlayout issue related bug? I'm using constraintlayout v2.0.2
i
The layout bounds of your TextView seems very small 🙂
o
This bug is not 100% reproduceable, switching back and forth will give different results. Sometimes it will just show fine.
@Ian Lake the width is set to wrap_content
l
@Orhan Tozan Do you have custom font? If you do, what heppens when you remove custom font?
o
This is the same screen, now it loads just fine:
@Lazar Ristic91 yes Im using a custom font (Helvetica Neueu), will try with it removed
With custom font removed. it still happens:
l
Can you share this part of the code in xml if you have?
o
@Lazar Ristic91 sure
Copy code
<TextView
            android:id="@+id/start_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            android:text="@{viewModel.startDate}"
            app:layout_constraintStart_toEndOf="@id/left_label_guideline"
            app:layout_constraintTop_toBottomOf="@+id/barrier6"
            tools:text="Do 5 dec. 2019" />

        <TextView
            android:id="@+id/start_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text='@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent ? ((ViewCalendarEventExtraTimeOptions.RegularEvent) viewModel.extraTimeOptions).startTime : ""}'
            android:textAppearance="@style/TextAppearance.Hello247.Body1"
            app:isVisible="@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent}"
            app:layout_constraintEnd_toStartOf="@+id/right_bound_guideline"
            app:layout_constraintTop_toTopOf="@+id/start_date"
            tools:text="17:30" />

        <TextView
            android:id="@+id/end_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="24dp"
            android:text="@{viewModel.endDate}"
            android:textAppearance="@style/TextAppearance.Hello247.Body1"
            app:layout_constraintStart_toStartOf="@+id/start_date"
            app:layout_constraintTop_toBottomOf="@+id/start_date"
            tools:text="Do 5 dec. 2019" />

        <TextView
            android:id="@+id/end_time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text='@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent ? ((ViewCalendarEventExtraTimeOptions.RegularEvent) viewModel.extraTimeOptions).endTime : ""}'
            android:textAppearance="@style/TextAppearance.Hello247.Body1"
            app:isVisible="@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent}"
            app:layout_constraintEnd_toStartOf="@+id/right_bound_guideline"
            app:layout_constraintTop_toTopOf="@+id/end_date"
            tools:text="18:30" />
l
@Orhan Tozan 1. Why do you have
constraintEnd
at
start_time
and
end_time
and you do not have
constraintStart
? Can you try with out
constraintEnd
? 2. Can you put this into function
Copy code
@{viewModel.extraTimeOptions instanceof ViewCalendarEventExtraTimeOptions.RegularEvent ? ((ViewCalendarEventExtraTimeOptions.RegularEvent) viewModel.extraTimeOptions).startTime : ""}
I had bad experience with coding in xml. Please replay me with results when you try this.
o
I switched from constraintlayout 2.0.2 to 1.1.3 and it fixed both of my issues. Want to share this to let other's know there might still be issues with Constraintlayout v2.
👍 1