In my MainView
, When I click on "Connect Button"
, ConnectView
is perfectly displayed, but inside the MyDeviceView
, When I click on DeviceConfigurationView
or BLEDeviceConfigurationView
, they goes back to parent page MainView
.
This is only available in iOS15, so it's not a problem in previous versions
// MainView
VStack {
// Connect button
NavigationLink(destination: ConnectView(), label: {
Text("connect")
})
MyDeviceView()
}
struct MyDeviceView: View {
@EnvironmentObject private var ioTControllerService: IoTControllerService
@EnvironmentObject private var onboardService: BLEService
var body: some View {
BaseList(sections: ioTControllerService.iotDeviceListSection) { row in
NavigationLink(destination: DeviceConfigurationView(serialNumber: row.serialNumber, deviceUUID: row.id, viewModel: DeviceConfigurationViewViewModel())) {
BaseRowView(title: row.title)
}
}
BaseList(sections: onboardService.bleDeviceListSections) { row in
NavigationLink(destination: BLEDeviceConfigurationView(deviceUUID: row.id, viewModel: BLEDeviceConfigurationViewViewModel()).onAppear{
onboardService.connect(to: row.id)
}) {
BaseRowView(title: row.title)
}
}
}
}
struct BaseList<Content: View>: View {
// MARK: - Properties
/// Data model
var sections: [BaseListSection]
/// Custom row view
var contentProvider: (BaseListSection.Row) -> Content
// MARK: - Life Cycle
/// Base List Initializer
/// - Parameters:
/// - sections: Sections data
/// - contentProvider: Row view
init(sections: [BaseListSection], @ViewBuilder contentProvider: @escaping (BaseListSection.Row) -> Content) {
self.sections = sections
self.contentProvider = contentProvider
}
var body: some View {
List {
ForEach(sections) { section in
Section(header: Text(section.sectionTitle)) {
ForEach(section.rows) { row in
self.contentProvider(row)
}
}
}
}
.listStyle(GroupedListStyle())
}
}