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

feat(ErrorBanner): offline banner #478

Merged
merged 3 commits into from
Oct 22, 2024
Merged

feat(ErrorBanner): offline banner #478

merged 3 commits into from
Oct 22, 2024

Conversation

KaylaBrady
Copy link
Collaborator

@KaylaBrady KaylaBrady commented Oct 18, 2024

Summary

Ticket: Offline error banner

What is this PR for?

This PR adds an error banner that appears when a user is offline.

I used the following resources as a basis for this implementation:

I drifted from the Blog post's approach in a few ways:

  • It publishes NetworkStatus as a flow. We already have an ErrorBannerState flow, so rather than introducing an intermediate flow, NetworkStatus changes just update the ErrorBannerState flow directly.
  • It implements the network monitor on the ios-side in Swift - I incorporated the approach in the linked GH comment so the monitoring could be done entirely in kotlin.

Testing

What testing have you done?

  • Added unit tests
  • Ran locally turning airplane mode on & off.

I included the android implementation from the blog post but did not test it.
image

@KaylaBrady KaylaBrady requested a review from a team as a code owner October 18, 2024 19:58
@KaylaBrady KaylaBrady requested a review from EmmaSimon October 18, 2024 19:58
Copy link
Contributor

@EmmaSimon EmmaSimon left a comment

Choose a reason for hiding this comment

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

Nothing major, but I have a couple points on the layout. All the logic changes look great.

@@ -46,6 +46,12 @@ struct ErrorBanner: View {
}
.frame(minHeight: minHeight)
}
case .networkError:
ErrorCard { HStack {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the default alignment in this HStack not center? It looks kinda like the image is below the centerline of the text.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added some borders to each view - I think looks it is centered when accounting for the full line height of the text.
image

I swapped in HStack(alignment: .center) and didn't notice a difference

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay yeah, I think it's just a matter of the icon being slightly bottom heavy. Thanks for checking!

@@ -14,6 +14,6 @@ internal fun createDataStore(context: Context): DataStore<Preferences> =
fun initKoin(appVariant: AppVariant, nativeModule: Module, context: Context) {
startKoin {
androidContext(context)
modules(appModule(appVariant) + platformModule() + nativeModule)
modules(platformModule() + appModule(appVariant) + nativeModule)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, but why were these swapped?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh this isn't actually necessary. At first I tried having ErrorBannerStateRepo call subscribeToNetworkStatusChanges on init, but that was causing dependency injection issues with BeanNotFound errors. I thought maybe the platformModule needed to be called first here since appModule depends on it, but that didn't end up fixing the issue, and I just opted to call subscribeToNetworkStatusChanges from the ViewModel instead.

case .networkError:
ErrorCard { HStack {
Image(systemName: "wifi.slash")
Text("Unable to connect")
Copy link
Contributor

Choose a reason for hiding this comment

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

Because this has no reload button like the other two banners, it also has no Spacer(), so we're getting the awkward squished banner. If you toss a Spacer() at the end here, I think that'll get it to take up the full width.

Image(systemName: "wifi.slash")
Text("Unable to connect")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I'd put these braces on the same line 😛

import shared
import XCTest

final class ErrorBannerViewModelTests: XCTestCase {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this!

@KaylaBrady KaylaBrady merged commit 10d2bad into main Oct 22, 2024
7 checks passed
@KaylaBrady KaylaBrady deleted the kb-offline branch October 22, 2024 14:32
KaylaBrady added a commit that referenced this pull request Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants