-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
12 deletions.
There are no files selected for viewing
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,45 @@ | ||
// | ||
// ViewProxy.swift | ||
// SwiftUIPagerExample | ||
// | ||
// Created by Fernando Moya de Rivas on 27/12/20. | ||
// Copyright © 2020 Fernando Moya de Rivas. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Proxy to inject an `ObservableObject` as a `StateObject` | ||
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) | ||
struct StateObjectViewProxy<Property: ObservableObject, Content: View>: View { | ||
|
||
@StateObject private var observableProperty: Property | ||
let content: (Property) -> Content | ||
|
||
init(property: Property, @ViewBuilder content: @escaping (Property) -> Content) { | ||
self._observableProperty = StateObject(wrappedValue: property) | ||
self.content = content | ||
} | ||
|
||
var body: some View { | ||
content(observableProperty) | ||
} | ||
|
||
} | ||
|
||
/// Proxy to inject an `ObservableObject` as a `ObservedObject` | ||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) | ||
struct ObservedObjectViewProxy<Property: ObservableObject, Content: View>: View { | ||
|
||
@ObservedObject private var observableProperty: Property | ||
let content: (Property) -> Content | ||
|
||
init(property: Property, @ViewBuilder content: @escaping (Property) -> Content) { | ||
self.observableProperty = property | ||
self.content = content | ||
} | ||
|
||
var body: some View { | ||
content(observableProperty) | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,7 +1,2 @@ | ||
### Features | ||
- New modifier to switch back to `singlePagination` and provide a reveal `ratio` | ||
- New modifiers to keep track of the dragging `onDraggingChanged` and `onDraggingEnded` | ||
- New modifier to disable `bounces` | ||
|
||
### Fixes | ||
- Smoother scroll | ||
- Workaround to use `StateObject` if possible |