-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize partial sheet using binding (#67)
* PartialSheetAddModifier initial implementation * Add onDismiss handling to the modifier * Public modifier * Rewritten ViewModifier, added example * Added method comment * Make update fields optional * Update sheet content while shown Co-authored-by: woko <[email protected]>
- Loading branch information
Showing
5 changed files
with
124 additions
and
1 deletion.
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
58 changes: 58 additions & 0 deletions
58
Example/PartialSheetExample/Examples/ViewModifierExample.swift
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,58 @@ | ||
// | ||
// ViewModifierExample.swift | ||
// PartialSheetExample | ||
// | ||
// Created by woko on 03/09/2020. | ||
// Copyright © 2020 Swift. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ViewModifierExample: View { | ||
@State var isSheetShown = false | ||
@State var viewContent = "Initial content" | ||
var body: some View { | ||
HStack { | ||
Spacer() | ||
Button(action: { | ||
self.isSheetShown = true | ||
}, label: { | ||
Text("Display the ViewModifier sheet") | ||
}) | ||
.padding() | ||
Spacer() | ||
} | ||
.navigationBarTitle("ViewModifier Example") | ||
.navigationViewStyle(StackNavigationViewStyle()) | ||
.partialSheet(isPresented: $isSheetShown) { | ||
ViewModifierView(content: self.$viewContent) | ||
.padding(.vertical, 50) | ||
} | ||
} | ||
} | ||
|
||
struct ViewModifierExample_Previews: PreviewProvider { | ||
static var previews: some View { | ||
NavigationView { | ||
ViewModifierExample() | ||
} | ||
.addPartialSheet() | ||
.navigationViewStyle(StackNavigationViewStyle()) | ||
.environmentObject(PartialSheetManager()) | ||
} | ||
} | ||
|
||
struct ViewModifierView: View { | ||
@Binding var content: String | ||
|
||
var body: some View { | ||
VStack { | ||
Text(content) | ||
Button(action: { | ||
self.content = "Inner content" | ||
}, label: { | ||
Text("Change content") | ||
}) | ||
} | ||
} | ||
} |
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