mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 08:32:53 +02:00
Finish extraction
- Moves SwiftUI code out of Riot and into RiotSwiftUI which has no dependency on Matrix SDK. - Git wasn't smart enough to see the file moves. Most feature function has remain unchanged. 1 change I did make was remove NotificationSettingsViewModel's dependence on MxPushRule, so that the view model could be moved into RiotSwiftUI. - Add LocaleProvider to abstract VectorL10n's use of Matrix SDK language so it can be used in RiotSwiftUI. - Split Theme into UKit/SwiftUI version to remove RiotSwiftUI's dependence on ThemeService and ThemeV1. - Migrated from ThemeObserver to ThemePublisher. We push updates to ThemePublisher so that we can remove ThemeService as dependency. - Add .DS_Store to .gitignore
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct FormItemButtonStyle: ButtonStyle {
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
func makeBody(configuration: Self.Configuration) -> some View {
|
||||
configuration.label
|
||||
.background(configuration.isPressed ? theme.colors.system : theme.colors.background)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
.font(theme.fonts.body)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct FormPickerItem: View {
|
||||
|
||||
typealias TapCallback = () -> Void
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
|
||||
var title: String
|
||||
var selected: Bool
|
||||
var onTap: TapCallback?
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
onTap?()
|
||||
} label: {
|
||||
VStack {
|
||||
Spacer()
|
||||
HStack {
|
||||
Text(title)
|
||||
Spacer()
|
||||
if selected {
|
||||
Image("checkmark")
|
||||
.foregroundColor(theme.colors.accent)
|
||||
}
|
||||
}
|
||||
.padding(.trailing)
|
||||
Spacer()
|
||||
Divider()
|
||||
}
|
||||
.padding(.leading)
|
||||
}
|
||||
.buttonStyle(FormItemButtonStyle())
|
||||
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, idealHeight: 44, alignment: .leading)
|
||||
.fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct FormPickerItem_Previews: PreviewProvider {
|
||||
|
||||
static let items = ["Item 1", "Item 2", "Item 3"]
|
||||
static var selected: String = items[0]
|
||||
static var previews: some View {
|
||||
VectorForm {
|
||||
ForEach(items, id: \.self) { item in
|
||||
FormPickerItem(title: item, selected: selected == item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct FormSectionFooter: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
var text: String
|
||||
|
||||
var body: some View {
|
||||
Text(text)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.padding(.top)
|
||||
.padding(.leading)
|
||||
.padding(.trailing)
|
||||
.font(theme.fonts.callout)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct FormSectionFooter_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VectorForm {
|
||||
SwiftUI.Section(footer: FormSectionFooter(text: "Please note that mentions & keyword notifications are not available in encrypted rooms on mobile.")) {
|
||||
FormPickerItem(title: "Item 1", selected: false)
|
||||
FormPickerItem(title: "Item 2", selected: false)
|
||||
FormPickerItem(title: "Item 3", selected: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct FormSectionHeader: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
var text: String
|
||||
|
||||
var body: some View {
|
||||
Text(text)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.padding(.top, 32)
|
||||
.padding(.leading)
|
||||
.padding(.bottom, 8)
|
||||
.font(theme.fonts.subheadline)
|
||||
.textCase(.uppercase)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct FormSectionHeader_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VectorForm {
|
||||
SwiftUI.Section(header: FormSectionHeader(text: "Section Header")) {
|
||||
FormPickerItem(title: "Item 1", selected: false)
|
||||
FormPickerItem(title: "Item 2", selected: false)
|
||||
FormPickerItem(title: "Item 3", selected: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 14.0.0, *)
|
||||
struct RoomNotificationSettings: View {
|
||||
|
||||
@ObservedObject var viewModel: RoomNotificationSettingsSwiftUIViewModel
|
||||
|
||||
let presentedModally: Bool
|
||||
|
||||
@ViewBuilder
|
||||
private var leftButton: some View {
|
||||
if presentedModally {
|
||||
Button(VectorL10n.cancel) {
|
||||
viewModel.process(viewAction: .cancel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var rightButton: some View {
|
||||
Button(VectorL10n.save) {
|
||||
viewModel.process(viewAction: .save)
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VectorForm {
|
||||
if let avatarData = viewModel.viewState.avatarData as? AvatarInputType {
|
||||
RoomNotificationSettingsHeader(
|
||||
avatarData: avatarData,
|
||||
displayName: viewModel.viewState.displayName
|
||||
)
|
||||
}
|
||||
SwiftUI.Section(
|
||||
header: FormSectionHeader(text: VectorL10n.roomNotifsSettingsNotifyMeFor),
|
||||
footer: FormSectionFooter(text: viewModel.viewState.roomEncryptedString)
|
||||
) {
|
||||
ForEach(viewModel.viewState.notificationOptions) { option in
|
||||
FormPickerItem(title: option.title, selected: viewModel.viewState.notificationState == option) {
|
||||
viewModel.process(viewAction: .selectNotificationState(option))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.activityIndicator(show: viewModel.viewState.saving)
|
||||
.navigationBarTitle(VectorL10n.roomDetailsNotifs)
|
||||
.navigationBarItems(
|
||||
leading: leftButton,
|
||||
trailing: rightButton
|
||||
)
|
||||
.onAppear {
|
||||
viewModel.process(viewAction: .load)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct RoomNotificationSettings_Previews: PreviewProvider {
|
||||
|
||||
static let mockViewModel = RoomNotificationSettingsSwiftUIViewModel(
|
||||
roomNotificationService: MockRoomNotificationSettingsService.example,
|
||||
avatarData: MockAvatarInput.example,
|
||||
displayName: MockAvatarInput.example.displayName,
|
||||
roomEncrypted: true
|
||||
)
|
||||
|
||||
static var previews: some View {
|
||||
Group {
|
||||
NavigationView {
|
||||
RoomNotificationSettings(viewModel: mockViewModel, presentedModally: true)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.addDependency(MockAvatarService.example)
|
||||
}
|
||||
NavigationView {
|
||||
RoomNotificationSettings(viewModel: mockViewModel, presentedModally: true)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.theme(ThemeIdentifier.dark)
|
||||
.addDependency(MockAvatarService.example)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct RoomNotificationSettingsHeader: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
var avatarData: AvatarInputType
|
||||
var displayName: String?
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
Spacer()
|
||||
VStack(alignment: .center) {
|
||||
AvatarImage(avatarData: avatarData, size: .xxLarge)
|
||||
if let displayName = displayName {
|
||||
Text(displayName)
|
||||
.font(theme.fonts.title3SB)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
.textCase(nil)
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.padding(.top, 36)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct RoomNotificationSettingsHeader_Previews: PreviewProvider {
|
||||
static let name = "Element"
|
||||
static var previews: some View {
|
||||
RoomNotificationSettingsHeader(avatarData: MockAvatarInput.example, displayName: name)
|
||||
.addDependency(MockAvatarService.example)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct VectorForm<Content: View>: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
var content: () -> Content
|
||||
|
||||
init(@ViewBuilder content: @escaping () -> Content) {
|
||||
self.content = content
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 0, content: content)
|
||||
}
|
||||
.frame(
|
||||
minWidth: 0,
|
||||
maxWidth: .infinity,
|
||||
minHeight: 0,
|
||||
maxHeight: .infinity,
|
||||
alignment: .top
|
||||
)
|
||||
.background(theme.colors.system)
|
||||
.edgesIgnoringSafeArea(.bottom)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct VectorForm_Previews: PreviewProvider {
|
||||
|
||||
static var previews: some View {
|
||||
Group {
|
||||
VectorForm {
|
||||
SwiftUI.Section(header: FormSectionHeader(text: "Section Header")) {
|
||||
FormPickerItem(title: "Item 1", selected: true)
|
||||
FormPickerItem(title: "Item 2", selected: false)
|
||||
FormPickerItem(title: "Item 3", selected: false)
|
||||
}
|
||||
}
|
||||
VectorForm {
|
||||
FormPickerItem(title: "Item 1", selected: true)
|
||||
}
|
||||
.theme(ThemeIdentifier.dark)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user