Skip to content

Commit

Permalink
Merge pull request #1837 from nextcloud/fix-nc-button-swift-ui
Browse files Browse the repository at this point in the history
Make NCButton (SwiftUI) height flexible
  • Loading branch information
SystemKeeper authored Oct 18, 2024
2 parents cae7818 + ec511e9 commit 25ebf7e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 44 deletions.
16 changes: 9 additions & 7 deletions NextcloudTalk/NCButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import Foundation
import UIKit
import SwiftUI

let NCButtonHorizontalPadding: CGFloat = 16
let NCButtonVerticalPadding: CGFloat = 8
let NCButtonCornerRadius: CGFloat = 8

struct NCButtonSwiftUI: View {
@State var title: String
@State var action: () -> Void
@State var style: NCButtonStyle
@State var height: CGFloat
@Binding var disabled: Bool

enum NCButtonStyle: Int {
Expand All @@ -26,18 +29,17 @@ struct NCButtonSwiftUI: View {
Text(title)
.bold()
.foregroundColor(titleColorForStyle(style: style).opacity(disabled ? 0.5 : 1))
.padding(.vertical, 4)
.padding(.horizontal, 40)
.frame(height: height)
.fixedSize(horizontal: false, vertical: true)
.padding(.vertical, NCButtonVerticalPadding)
.padding(.horizontal, NCButtonHorizontalPadding)
.background(backgroundColorForStyle(style: style).opacity(disabled ? 0.5 : 1))
.cornerRadius(height / 2)
.cornerRadius(NCButtonCornerRadius)
.overlay(
RoundedRectangle(cornerRadius: 20)
RoundedRectangle(cornerRadius: NCButtonCornerRadius)
.stroke(borderColorForStyle(style: style).opacity(disabled ? 0.5 : 1), lineWidth: borderWidthForStyle(style: style))
)
})
.disabled(disabled)

}

func backgroundColorForStyle(style: NCButtonStyle) -> Color {
Expand Down
65 changes: 28 additions & 37 deletions NextcloudTalk/UserStatusMessageSwiftUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,36 +103,34 @@ struct UserStatusMessageSwiftUIView: View {
}
}
}
if !UIDevice.current.orientation.isLandscape {
VStack(spacing: 10) {
NCButtonSwiftUI(title: NSLocalizedString("Clear status message",
comment: ""),
action: clearActiveUserStatus,
style: .tertiary, height: 40,
disabled: Binding.constant(!userHasStatusSet))
NCButtonSwiftUI(title: NSLocalizedString("Set status message", comment: ""),
action: setActiveUserStatus,
style: .primary, height: 40,
disabled: Binding.constant(selectedMessage.isEmpty && selectedIcon.isEmpty))
.padding(.bottom, 16)
}
} else {
HStack(spacing: 10) {
Spacer()
NCButtonSwiftUI(title: NSLocalizedString("Clear status message",
comment: ""),
action: clearActiveUserStatus,
style: .tertiary, height: 40,
disabled: Binding.constant(!userHasStatusSet))
.padding(.bottom, 16)
NCButtonSwiftUI(title: NSLocalizedString("Set status message", comment: ""),
action: setActiveUserStatus,
style: .primary, height: 40,
disabled: Binding.constant(selectedMessage.isEmpty && selectedIcon.isEmpty))
.padding(.bottom, 16)
Spacer()
}
}
if !UIDevice.current.orientation.isLandscape {
VStack(spacing: 10) {
NCButtonSwiftUI(title: NSLocalizedString("Clear status message", comment: ""),
action: clearActiveUserStatus,
style: .tertiary,
disabled: Binding.constant(!userHasStatusSet))
NCButtonSwiftUI(title: NSLocalizedString("Set status message", comment: ""),
action: setActiveUserStatus,
style: .primary,
disabled: Binding.constant(selectedMessage.isEmpty && selectedIcon.isEmpty))
.padding(.bottom, 16)
}
} else {
HStack(spacing: 10) {
Spacer()
NCButtonSwiftUI(title: NSLocalizedString("Clear status message", comment: ""),
action: clearActiveUserStatus,
style: .tertiary,
disabled: Binding.constant(!userHasStatusSet))
.padding(.bottom, 16)
NCButtonSwiftUI(title: NSLocalizedString("Set status message", comment: ""),
action: setActiveUserStatus,
style: .primary,
disabled: Binding.constant(selectedMessage.isEmpty && selectedIcon.isEmpty))
.padding(.bottom, 16)
Spacer()
}
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
Expand Down Expand Up @@ -335,11 +333,4 @@ struct UserStatusMessageSwiftUIView: View {

return NSLocalizedString("Don't clear", comment: "")
}

}

struct UserStatusMessageSwiftUIView_Previews: PreviewProvider {
static var previews: some View {
UserStatusMessageSwiftUIView(changed: Binding.constant(false))
}
}

0 comments on commit 25ebf7e

Please sign in to comment.