-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/swiftformat
# Conflicts: # WaiterRobot/Ui/Core/Navigation.swift
- Loading branch information
Showing
16 changed files
with
294 additions
and
176 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// PullToRefresh.swift | ||
// WaiterRobot | ||
// | ||
// Created by Fabian Schedler on 20.11.23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PullToRefresh: View { | ||
let coordinateSpaceName: String | ||
let isRefreshing: Bool | ||
let onRefresh: () -> Void | ||
|
||
@State var needRefresh: Bool = false | ||
|
||
var body: some View { | ||
if isRefreshing { | ||
EmptyView() | ||
} else { | ||
GeometryReader { geo in | ||
if geo.frame(in: .named(coordinateSpaceName)).midY > 50 { | ||
Spacer() | ||
.onAppear { | ||
needRefresh = true | ||
print("NeedRefresh") | ||
} | ||
} else if geo.frame(in: .named(coordinateSpaceName)).maxY < 10 { | ||
Spacer() | ||
.onAppear { | ||
if needRefresh { | ||
onRefresh() | ||
needRefresh = false | ||
print("RefreshStarted") | ||
} | ||
} | ||
} | ||
|
||
let pullProgress = max(0, min(50, geo.frame(in: .named(coordinateSpaceName)).midY)) / 50 | ||
|
||
HStack { | ||
Spacer() | ||
ProgressView() | ||
.opacity(pullProgress) | ||
.controlSize(.large) | ||
.tint(.gray) | ||
.padding(.bottom, 50) | ||
Spacer() | ||
} | ||
}.padding(.top, -50) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// RefreshableScrollView.swift | ||
// WaiterRobot | ||
// | ||
// Created by Fabian Schedler on 20.11.23. | ||
// | ||
|
||
import shared | ||
import SwiftUI | ||
|
||
struct RefreshableScrollView<Content: View>: View { | ||
private let isRefreshing: Bool | ||
private let onRefresh: () -> Void | ||
private let content: () -> Content | ||
|
||
init( | ||
isRefreshing: Bool, | ||
onRefresh: @escaping () -> Void, | ||
@ViewBuilder content: @escaping () -> Content | ||
) { | ||
self.isRefreshing = isRefreshing | ||
self.onRefresh = onRefresh | ||
self.content = content | ||
} | ||
|
||
init( | ||
resource: Resource<some Any>, | ||
onRefresh: @escaping () -> Void, | ||
@ViewBuilder content: @escaping () -> Content | ||
) { | ||
self.init(for: onEnum(of: resource), onRefresh: onRefresh, content: content) | ||
} | ||
|
||
init( | ||
for resource: Skie.org_datepollsystems_waiterrobot__shared.Resource.__Sealed<some Any>, | ||
onRefresh: @escaping () -> Void, | ||
@ViewBuilder content: @escaping () -> Content | ||
) { | ||
if case .loading = resource { | ||
self.init(isRefreshing: true, onRefresh: onRefresh, content: content) | ||
} else { | ||
self.init(isRefreshing: false, onRefresh: onRefresh, content: content) | ||
} | ||
} | ||
|
||
var body: some View { | ||
ScrollView { | ||
PullToRefresh( | ||
coordinateSpaceName: "PullToRefresh", | ||
isRefreshing: isRefreshing, | ||
onRefresh: onRefresh | ||
) | ||
if isRefreshing { | ||
ProgressView() | ||
.controlSize(.large) | ||
.tint(.gray) | ||
} | ||
content() | ||
}.coordinateSpace(name: "PullToRefresh") | ||
} | ||
} | ||
|
||
struct Refreshing_Preview: PreviewProvider { | ||
static var previews: some View { | ||
RefreshableScrollView( | ||
isRefreshing: true, | ||
onRefresh: {} | ||
) { | ||
Text("Refreshing") | ||
} | ||
} | ||
} | ||
|
||
struct PullToRefresh_Preview: PreviewProvider { | ||
static var previews: some View { | ||
RefreshableScrollView( | ||
isRefreshing: false, | ||
onRefresh: {} | ||
) { | ||
Text("Pull to refresh") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.