FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Jetchat] Moves to Scaffold and Compose drawer content by JoseAlcerreca · Pull Request #263 · android/compose-samples · GitHub

[Jetchat] Moves to Scaffold and Compose drawer content - #263

Closed
JoseAlcerreca wants to merge 5 commits into
android:dev_alpha07from
JoseAlcerreca:dev_jetchat_androidview
Closed

[Jetchat] Moves to Scaffold and Compose drawer content #263
JoseAlcerreca wants to merge 5 commits into
android:dev_alpha07from
JoseAlcerreca:dev_jetchat_androidview

Conversation

Copy link
Copy Markdown
Contributor

No description provided.

Change-Id: I18d6c90b947fc2cc98c7d2c2683f1954ace200ed
Change-Id: I10a769b54254f94ff67bf9905bc1b736bd6d1b1f
Change-Id: I7f2adb8970cba9f2a91467367e4e39328c609771
Change-Id: Ibad4143a1765e3418ddbda1f8bfdcfc7bf42d63d
Change-Id: I2e9becb5f7afaecc936f70b98c34f8b803eb847e

manuelvicnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for making the changes! This looks great

Added a comment about the usage of StateFlow. Thanks!


private val _userData = MutableLiveData<ProfileScreenState>()
val userData: LiveData<ProfileScreenState> = _userData
private val _userData = MutableStateFlow<ProfileScreenState?>(null)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This pattern is very common when migrating from LD to StateFlow but I'd discourage having a StateFlow of a nullable type. What about creating an empty ProfileScreenState for this?

Suggested change
private val _userData = MutableStateFlow<ProfileScreenState?>(null)
private val _userData = MutableStateFlow<ProfileScreenState>(
ProfileScreenState("", "", "", "", "") // Empty user to begin with
)

The view then should check userId.isEmpty() for showing the error state, or even better, have that function as an extension function on ProfileScreenState to indicate if it's the object is properly constructed or not.

The benefits of doing this might not be obvious for this example, but it's the right pattern to use. In this way, you avoid that you can emit null again for this StateFlow and handling nullability when collecting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think we're trying to avoid null too much, this is an acceptable case for it. An empty screen state doesn't mean the same thing as null. In the view I can do:

                        if (userData == null) {
                            ProfileError()

and display better data to the user than an empty profile. Or I would have to create an extension ProfileScreenState.isEmpty() or something similar which is wasteful.

In a real app you would probably have this data wrapped into a resource sealed class. If there's a big problem with nullable types I would do that first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ping!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fine, leave it like this 🤷‍♂️

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL