-
Notifications
You must be signed in to change notification settings - Fork 1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,12 @@ struct ErrorBanner: View { | |
} | ||
.frame(minHeight: minHeight) | ||
} | ||
case .networkError: | ||
ErrorCard { HStack { | ||
Image(systemName: "wifi.slash") | ||
Text("Unable to connect") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
}} | ||
case nil: | ||
// for some reason, .collect on an EmptyView doesn't work | ||
EmptyView() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// ErrorBannerViewModelTests.swift | ||
// iosAppTests | ||
// | ||
// Created by Kayla Brady on 10/18/24. | ||
// Copyright © 2024 MBTA. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
@testable import iosApp | ||
import shared | ||
import XCTest | ||
|
||
final class ErrorBannerViewModelTests: XCTestCase { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding this! |
||
func testActivateSubscribesToNetworkChanges() async { | ||
let onSubscribeExp = XCTestExpectation(description: "onSubscribe called") | ||
let repo = MockErrorBannerStateRepository(state: nil, onSubscribeToNetworkChanges: { onSubscribeExp.fulfill() }) | ||
let errorVM = ErrorBannerViewModel( | ||
errorRepository: repo, | ||
initialLoadingWhenPredictionsStale: false, | ||
skipListeningForStateChanges: true | ||
) | ||
await errorVM.activate() | ||
wait(for: [onSubscribeExp], timeout: 1) | ||
Check notice on line 24 in iosApp/iosAppTests/ViewModels/ErrorBannerViewModelTests.swift Xcode Cloud / MBTA Transit Staging | PR Branch Workflow | iosAppRetries - iOSiosApp/iosAppTests/ViewModels/ErrorBannerViewModelTests.swift#L24
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package com.mbta.tid.mbta_app | ||
|
||
import com.mbta.tid.mbta_app.network.INetworkConnectivityMonitor | ||
import com.mbta.tid.mbta_app.network.NetworkConnectivityMonitor | ||
import com.mbta.tid.mbta_app.utils.AndroidSystemPaths | ||
import com.mbta.tid.mbta_app.utils.SystemPaths | ||
import org.koin.dsl.module | ||
|
||
fun platformModule() = module { | ||
includes( | ||
module { single { createDataStore(get()) } }, | ||
module { single<SystemPaths> { AndroidSystemPaths(get()) } } | ||
module { single<SystemPaths> { AndroidSystemPaths(get()) } }, | ||
module { single<INetworkConnectivityMonitor> { NetworkConnectivityMonitor(get()) } } | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.mbta.tid.mbta_app.network | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.content.Context.CONNECTIVITY_SERVICE | ||
import android.net.ConnectivityManager | ||
import android.net.Network | ||
|
||
class NetworkConnectivityMonitor(context: Context) : INetworkConnectivityMonitor { | ||
private var networkCallback: ConnectivityManager.NetworkCallback? = null | ||
private val connectivityManager = | ||
context.getSystemService(CONNECTIVITY_SERVICE) as ConnectivityManager | ||
|
||
@SuppressLint("MissingPermission") | ||
// Permission is included in AndroidManifest.xml | ||
override fun registerListener(onNetworkAvailable: () -> Unit, onNetworkLost: () -> Unit) { | ||
networkCallback = | ||
object : ConnectivityManager.NetworkCallback() { | ||
override fun onAvailable(network: Network) { | ||
onNetworkAvailable() | ||
} | ||
|
||
override fun onUnavailable() { | ||
onNetworkLost() | ||
} | ||
|
||
override fun onLost(network: Network) { | ||
onNetworkLost() | ||
} | ||
} | ||
networkCallback?.let { connectivityManager.registerDefaultNetworkCallback(it) } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.mbta.tid.mbta_app.network | ||
|
||
/** Observe changes in the device's network connectivity. */ | ||
interface INetworkConnectivityMonitor { | ||
fun registerListener(onNetworkAvailable: () -> Unit, onNetworkLost: () -> Unit) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
package com.mbta.tid.mbta_app | ||
|
||
import com.mbta.tid.mbta_app.network.INetworkConnectivityMonitor | ||
import com.mbta.tid.mbta_app.network.NetworkConnectivityMonitor | ||
import com.mbta.tid.mbta_app.utils.IOSSystemPaths | ||
import com.mbta.tid.mbta_app.utils.SystemPaths | ||
import org.koin.dsl.module | ||
|
||
fun platformModule() = module { | ||
includes( | ||
module { single { createDataStore() } }, | ||
module { single<SystemPaths> { IOSSystemPaths() } } | ||
module { single<SystemPaths> { IOSSystemPaths() } }, | ||
module { single<INetworkConnectivityMonitor> { NetworkConnectivityMonitor() } } | ||
) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I swapped in
HStack(alignment: .center)
and didn't notice a differenceThere was a problem hiding this comment.
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!