Search results for

swiftui

16,582 results found

Post

Replies

Boosts

Views

Activity

Deep Linking and State Restauration with SwiftUI
I wonder how to navigate to a specific UI state programmatically for deep linking or state restoration purposes when using `NavigationView` and `TabbedView`. I guess `TabbedView(selection: $selectedTab)` needs to be used, and `$selectedTab` could somehow leverage `Publishers.SwitchToLatest` to either set the value from the outside (a publisher passed as initializer parameter), or from the inside (when user presses tabbar button). I‘m a bit vague on the details, but it sounds possible. Any suggestions?
0
0
1.2k
Jun ’19
How to pass optional @ViewBuilder parameter in SwiftUI?
My team delivers a UI SDK implemented with UIKit. I'm investigating the best practices for how to ship a framework with reusable UI controls implemented in SwiftUI.One feature I really like in SwiftUI is @ViewBuilder. I could see one path for us is to ship a TableViewCell (well, the replacement) which has our classic API with String and UILabel-like parameters, but also provide a @ViewBuilder parameter that lets the developer do more significant customizations than we support in the control.I have this working nicely, where the @ViewBuilder property is required. But, it does not support an optional parameter, which I think is necessary for the struct init(...) method to behave as expected. Per the Swift 5.1 fix, I should be able to init a struct with only the un-inited parameters; I should be able to ignore the optional or pre-defined parameters.Desired behavior:ObjectView(title: Hello, World)Current behavior:ObjectView(title: Hello, World, main: { EmptyView() })Working example where @ViewBuilder par
0
0
3.9k
Jun ’19
SwiftUI string interpolation and localisation
Hello,I was watching the WWDC video:Introducing SwiftUI: Building Your First Apphttps://developer.apple.com/videos/play/wwdc2019/204/The had some sample code at 48:32 for localising the string used in inText((room.capacity) people)They used a stringdict file, but didn't expand on the details of configuring the string (here's the file I created in plain xml):<?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd> <plist version=1.0> <dict> <key>%lld people</key> <dict> <key>NSStringLocalizedFormatKey</key> <string>%#@VARIABLE@</string> <key>VARIABLE</key> <dict> <key>NSStringFormatSpecTypeKey</key> <string>NSStringPluralRuleType</string> <key>NSStringFormatValueTypeKey</key> <string></string> <key>zero</key> <string></string> <key>one</key> <string></
7
0
5.9k
Jun ’19
Issue from RoomStore.swift file (Session: Introducing SwiftUI: Building Your First App)
Hello All,I am following the session Introducing SwiftUI: Building Your First App and building the Rooms App. In the RoomStore.swift file, I encountered an issue saying Cannot invoke 'send' with no argument. (As the image below)Anyone knows how should I resolve this issue? In case if the image doesn't show, here is the link: https://drive.google.com/file/d/1B87jxSiGr03PJGGUMOWeMBkuWJ4t_IoL/view?usp=sharingThank you!Linne
4
0
944
Jun ’19
How to animate a view without explicitly triggering model changes?
First, a little context. I was trying to create a simple animation of a view that pulsates indefinitely and found it to be a really frustrating experience, probably because I don’t yet understand the SwiftUI animation model correctly. If someone has a simple solution, please share.Anyway, it occurred to me that it would be nice to have a view modifier that you attach to a view to express the desire to “animate property X of the view from value ‘from’ to value ‘to’, starting at value ‘startingAt’, using animation ‘animation’. All the view needs to do is expose that property X, as a key path or maybe a binding, and SwiftUI does the rest.This would allow for an easy way to animate several properties independently but simultaneously, each with their own animation parameters, as well as a way to animate a group of properties together (the view exposes some property which it uses internally to control a group of properties).Is this something that’s already possible and easy to do? If so, how?Here’
3
0
1.5k
Jun ’19
Reply to Style a List
I've been trying to wrap my head around how I should think about SwiftUI today for creating apps. Mostly - I'm not sure how far I should use it, and I don't know that because I'm not sure where SwiftUI should end and the platforms specific APIs should begin.This quesiton is a perfect example.Say I use the List struct on iOS, which basically becomes a table view (not sure what it renders down to specifically - maybe it's not a table view at all). Then, say I want to modify things specific to what make table view great like the leading/trailing contextual actions, selected background views or something similar - what does that look like?Is SwiftUI meant to even support this?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’19
Reply to How to animate a view without explicitly triggering model changes?
Upon further reflection, I think the idea I suggested above (assuming it makes sense and that there’s no simpler way to do it already) could be enhanced by adding an ‘isActive’ boolean to the view modifier function ‘.animating(...)’ so that we can programmatically start or stop the animation.Moreover, since the animation is entirely under SwiftUI’s control, maybe those exposed properties should be marked with a property wrapper that gives SwiftUI read-write access but gives the view that exposes them read-only access.So, something like the following:struct SomeView { @AutoAnimated private var x: CGFloat // the compiler ensures that x is read-only to us but read-write to SwiftUI // .... } struct EnclosingView { @State private var xAnimActive = true // this view can set and change this value to control the animation life cycle SomeView() .animating(.x, from: /* some value */, to: /* some value */, startingAt: /* some value */, animation: /* some animation here */, active: xAnimActive)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’19
ForEach inside ScrollView doesn't take whole width
I'm trying to re-create UI of my current app using SwiftUI. And it is way more difficult than I initially though.I wanted to achieve card-like cells with some background behind them. I found that List doesn't support that, at least yet. Hopefully in future ListStyle will allow that.So I moved to ForEach inside ScrollView. I guess that isn't something which should be used in production for long tables but that should work for now. The problem I have is that ForeEach view doesn't take all the width ScrollView provides. I can set .frame(...) modifier but that will require hardcoding width which I definitely don't want to do.Any ideas how to force VStack take full width of the ScrollView? I tried to use ForeEach without VStack and it has the same issue. It seems like ScrollView (parent view) tells its child view (VStack) that its size is less that actual ScrollView's size. Provavly in a view chain there is an internal ScrollContentView, with size less than ScrollView size and based on tha info all its ch
0
0
1.5k
Jun ’19
Landmark SwiftUI MacOS demo project. Where can I download?
About this demo session:https://developer.apple.com/videos/play/wwdc2019/240/Is says that:see how to incorporate device-specific features and how to make changes in SwiftUI by following along with a starter project, available for download.But there is no project to download:The Landmark SwiftUI bellow is iOS onlyhttps://developer.apple.com/tutorials/swiftui/interfacing-with-uikitWhere can I download Landmark MacOS?Thanks
0
0
946
Jun ’19
Reply to How to animate a view without explicitly triggering model changes?
I nearly got a working implementation (well, in theory) but I got stuck because of a private API.import SwiftUI struct ContentView: View { var body: some View { CircleView() .animating(.s, // QQQ Not sure why the generic parameter Value could not be inferred from: 0.2, to: 0.8, startingAt: 0.3, animation: .basic(duration: 0.8, curve: .easeInEaseOut), isActive: true) } } struct CircleView: View { @AutoAnimated private var s: CGFloat var body: some View { Circle() .fill(Color.red) .scaleEffect(s) } } #if DEBUG struct ContentView_Previews : PreviewProvider { static var previews: some View { ContentView() } } #endif // =========================================== // // QQQ There should be an extension to ViewModifier that does work // nearly identical to that of the extension to View below, so that // we can call '.animating(...)' on the result of another view modifier. public extension ViewModifier {} // ==================== // public extension View { func animating<Value: BinaryFloatingPoint>(_ pr
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’19
Reply to SwiftUI dismiss model
Since `PresentationButton` is easy to use but hiding the state wich is undermining the predictive character of `SwiftUI` I have implemented it with an accessible `Binding`.public struct BindedPresentationButton<label, destination=>: View where Label: View, Destination: View { /// The state of the modal presentation, either `visibile` or `off`. private var showModal: Binding /// A `View` to use as the label of the button. public var label: Label /// A `View` to present. public var destination: Destination /// A closure to be invoked when the button is tapped. public var onTrigger: (() -> Void)? public init( showModal: Binding, label: Label, destination: Destination, onTrigger: (() -> Void)? = nil ) { self.showModal = showModal self.label = label self.destination = destination self.onTrigger = onTrigger } public var body: some View { Button(action: toggleModal) { label } .presentation( !showModal.value ? nil : Modal( destination, onDismiss: { self.toggleModal() } ) ) } private func toggleMo
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’19