Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 'changeToolbarColorOnScroll' crash #2089

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import androidx.lifecycle.Lifecycle.Event
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import androidx.webkit.WebSettingsCompat
Expand Down Expand Up @@ -114,6 +115,8 @@ import io.realm.kotlin.query.RealmQuery
import io.realm.kotlin.query.Sort
import io.realm.kotlin.types.RealmInstant
import io.realm.kotlin.types.RealmObject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.serialization.encodeToString
import org.jsoup.nodes.Document
import java.util.Calendar
Expand Down Expand Up @@ -489,7 +492,9 @@ fun Fragment.changeToolbarColorOnScroll(
valueAnimator = animateColorChange(oldColor, newColor, animate = true) { color ->
oldColor = color
toolbar.setBackgroundColor(color)
if (shouldUpdateStatusBar()) requireActivity().window.statusBarColor = color
if (shouldUpdateStatusBar()) {
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) { requireActivity().window.statusBarColor = color }
}
Comment on lines +495 to +497
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, this should have already been fixed, I don't understand.

There's a already a Dispatchers.Main inside animateColorChange(), there should be no point in adding a second one here, why is it not enough?

Also, there should be other lines of code that will crash if not on the main Thread such as toolbar.setBackgroundColor(color) and otherUpdates?.invoke(color). Do they not crash?

otherUpdates?.invoke(color)
}
}
Expand Down
Loading