fix: ShareExtension UI hack not works on iOS 15 issue

This commit is contained in:
CMK 2021-10-11 15:25:21 +08:00
parent 084524eb75
commit 575035daaf
1 changed files with 21 additions and 4 deletions

View File

@ -85,6 +85,7 @@ public struct ComposeView: View {
.frame(height: viewModel.toolbarHeight + 20) .frame(height: viewModel.toolbarHeight + 20)
.listRow(backgroundColor: Color(viewModel.backgroundColor)) .listRow(backgroundColor: Color(viewModel.backgroundColor))
} // end List } // end List
.listStyle(.plain)
.introspectTableView(customize: { tableView in .introspectTableView(customize: { tableView in
// tableView.keyboardDismissMode = .onDrag // tableView.keyboardDismissMode = .onDrag
tableView.verticalScrollIndicatorInsets.bottom = viewModel.toolbarHeight tableView.verticalScrollIndicatorInsets.bottom = viewModel.toolbarHeight
@ -101,7 +102,7 @@ public struct ComposeView: View {
.introspectTableView(customize: { tableView in .introspectTableView(customize: { tableView in
tableView.backgroundColor = .clear tableView.backgroundColor = .clear
}) })
.background(Color(viewModel.backgroundColor).ignoresSafeArea()) .overrideBackground(color: Color(viewModel.backgroundColor))
} // end GeometryReader } // end GeometryReader
} // end body } // end body
} }
@ -112,10 +113,26 @@ struct ComposeListViewFramePreferenceKey: PreferenceKey {
} }
extension View { extension View {
// hack for separator line
@ViewBuilder
func listRow(backgroundColor: Color) -> some View { func listRow(backgroundColor: Color) -> some View {
self.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) // expand list row to edge (set inset)
.listRowInsets(EdgeInsets(top: -1, leading: -1, bottom: -1, trailing: -1)) // then hide the separator
.background(backgroundColor) if #available(iOS 15, *) {
frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.listRowInsets(EdgeInsets(top: -1, leading: -1, bottom: -1, trailing: -1))
.background(backgroundColor)
.listRowSeparator(.hidden) // new API
} else {
frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.listRowInsets(EdgeInsets(top: -1, leading: -1, bottom: -1, trailing: -1)) // separator line hidden magic
.background(backgroundColor)
}
}
@ViewBuilder
func overrideBackground(color: Color) -> some View {
background(color.ignoresSafeArea())
} }
} }