Skip to content
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

more native macos UI / create button can now be at top instead of floating #62

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Sources/WishKit/Configuration+Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ extension Configuration {

public var addButtonInNavigationBar: String

public var refresh: String

public var refreshing: String

public init(
requested: String = Localization.default().requested,
pending: String = Localization.default().pending,
Expand Down Expand Up @@ -127,7 +131,9 @@ extension Configuration {
emailOptional: String = Localization.default().emailOptional,
emailRequired: String = Localization.default().emailRequired,
discardEnteredInformation: String = Localization.default().discardEnteredInformation,
addButtonInNavigationBar: String = Localization.default().addButtonInNavigationBar
addButtonInNavigationBar: String = Localization.default().addButtonInNavigationBar,
refresh: String = Localization.default().refresh,
refreshing: String = Localization.default().refreshing
) {
self.requested = requested
self.pending = pending
Expand Down Expand Up @@ -168,6 +174,8 @@ extension Configuration {
self.emailRequired = emailRequired
self.discardEnteredInformation = discardEnteredInformation
self.addButtonInNavigationBar = addButtonInNavigationBar
self.refresh = refresh
self.refreshing = refreshing
}

public static func `default`() -> Localization {
Expand Down Expand Up @@ -210,7 +218,9 @@ extension Configuration {
emailOptional: "Email (optional)",
emailRequired: "Email (required)",
discardEnteredInformation: "Discard entered information?",
addButtonInNavigationBar: "Create"
addButtonInNavigationBar: "Create",
refresh: "Refresh",
refreshing: "Refreshing.."
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/WishKit/ProjectSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ struct ProjectSettings {
let wishKitUrl = ProcessInfo.processInfo.environment["wishkit-url"]
return wishKitUrl ?? "https://www.wishkit.io/api"
}
static let sdkVersion = "4.4.0"
static let sdkVersion = "4.5.0"
}
22 changes: 12 additions & 10 deletions Sources/WishKit/SwiftUI/WishlistView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,18 @@ struct WishlistView: View {
Spacer()
HStack {
Spacer()
AddButton(buttonAction: createWishAction)
.padding([.bottom, .trailing], 20)
.sheet(isPresented: $showingCreateSheet) {
CreateWishView(
createActionCompletion: { wishModel.fetchList() },
closeAction: { self.showingCreateSheet = false }
)
.frame(minWidth: 500, idealWidth: 500, minHeight: 400, maxHeight: 600)
.background(backgroundColor)
}
if WishKit.config.buttons.addButton.location == .floating {
AddButton(buttonAction: createWishAction)
.padding([.bottom, .trailing], 20)
.sheet(isPresented: $showingCreateSheet) {
CreateWishView(
createActionCompletion: { wishModel.fetchList() },
closeAction: { self.showingCreateSheet = false }
)
.frame(minWidth: 500, idealWidth: 500, minHeight: 400, maxHeight: 600)
.background(backgroundColor)
}
}
}
}
}
Expand Down
83 changes: 57 additions & 26 deletions Sources/WishKit/SwiftUI/macOS/WishlistContainer+macOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ struct WishlistContainer: View {

@State
private var isRefreshing = false

@State
private var showingCreateSheet = false

@ObservedObject
private var wishModel: WishModel
Expand Down Expand Up @@ -54,41 +57,63 @@ struct WishlistContainer: View {
}

var segmentedControlView: some View {
ZStack {
HStack {
SegmentedView(selectedWishState: $listType)
.padding()
.padding(.leading, 5)
.frame(maxWidth: 300)

HStack {
Button(action: refreshList) {
if isRefreshing {
ProgressView()
.scaleEffect(0.4)
.progressViewStyle(CircularProgressViewStyle())
} else {
Image(systemName: "arrow.clockwise")
}
Spacer()

Button(action: refreshList) {
if isRefreshing {
Text(WishKit.config.localization.refreshing)
} else {
Text(WishKit.config.localization.refresh)
}
.buttonStyle(PlainButtonStyle())
.frame(width: 20, height: 20)
.padding(EdgeInsets(top: 0, leading: 315, bottom: 0, trailing: 0))
}
}

if WishKit.config.buttons.addButton.location == .navigationBar {
Button(action: { self.showingCreateSheet.toggle() }) {
Text(WishKit.config.localization.addButtonInNavigationBar)
}
.padding(.leading, 15)
.sheet(isPresented: $showingCreateSheet) {
CreateWishView(
createActionCompletion: { wishModel.fetchList() },
closeAction: { self.showingCreateSheet = false }
)
.frame(minWidth: 500, idealWidth: 500, minHeight: 400, maxHeight: 600)
.background(systemBackgroundColor)
}
}
}.padding(EdgeInsets(top: 15, leading: 5, bottom: 15, trailing: 15))
}

var noSegmentedControlView: some View {
Button(action: refreshList) {
if isRefreshing {
ProgressView()
.scaleEffect(0.4)
.progressViewStyle(CircularProgressViewStyle())
} else {
Image(systemName: "arrow.clockwise")
HStack {
Button(action: refreshList) {
if isRefreshing {
Text(WishKit.config.localization.refreshing)
} else {
Text(WishKit.config.localization.refresh)
}
}.padding(.trailing, WishKit.config.buttons.addButton.location == .floating ? 15 : 0)

if WishKit.config.buttons.addButton.location == .navigationBar {
Button(action: { self.showingCreateSheet.toggle() }) {
Text(WishKit.config.localization.addButtonInNavigationBar)
}
.padding(.leading, 15)
.sheet(isPresented: $showingCreateSheet) {
CreateWishView(
createActionCompletion: { wishModel.fetchList() },
closeAction: { self.showingCreateSheet = false }
)
.frame(minWidth: 500, idealWidth: 500, minHeight: 400, maxHeight: 600)
.background(systemBackgroundColor)
}
}
}
.buttonStyle(PlainButtonStyle())
.frame(width: 20, height: 20)
.padding(EdgeInsets(top: 15, leading: 0, bottom: 15, trailing: 0))
}.padding(EdgeInsets(top: 15, leading: 5, bottom: 15, trailing: 15))
}

var systemBackgroundColor: Color {
Expand All @@ -105,6 +130,12 @@ struct WishlistContainer: View {
}

return PrivateTheme.systemBackgroundColor.dark
@unknown default:
if let color = WishKit.theme.tertiaryColor {
return color.light
}

return PrivateTheme.systemBackgroundColor.light
}
}
}
Expand Down
Loading