|
I've been working on an app for some time to teach myself SwiftUI and Core Data. Would anyone be willing to take a look and help me understand a few things: 1) I'd like to switch to using @Binding for closing subviews, but can't seem to get it to work. 2) I would like to figure out how to best refactor for creating a few "edit" screens. Let me know and Thanks in advance. |
|
Hi Michael I'd be happy to help. is your code on github or somewhere to take a look? Richard |
|
Hi @rlong405 it's on github https://github.com/michaelrowe01/Card-Tracker.org Thanks for any feedback. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
Hi @michaelrowe01, In terms of dismissing subviews, a lot of your subviews are modals (sheets) and I see you have used
This is a perfectly fine way to dismiss a sheet. Are you looking to use bindings to toggle a bool back to false and close the sheet that way? There really is no need to use that method unless you particularly want to but happy to guide on how to do it if you'd like me to . Richard |
|
Then in terms of your edit screens, below is something to edit your recipient (I've assume this would be called from a new button on ViewEventsView). This would be a new view Note - I wouldn't normally NOT have the save function in the view but for ease have done that here. My main piece of advise across your code is to get your logic out of your views. - It's not essential right now but it will tidy things up a lot. I can help point you in the right direction on how to do that if you'd like Below is the code for the new edit view. Let me know if you need help with how to show this new view. You can call it as a sheet but I have assumed it will be pushed on the navigation view stack (and have dismissed it as such once the changes are made).
|
|
thanks for the thourough response. I do want to remove the .presentationMode as the app ends up closing the new Receipient modal, when I cancel the ContactsPicker. I can't seem to figure out how to stop that. I've never seen the State(initialValue:) function. That makes things much clearer. I will give it a shot this week and see if I can figure out how to write it up correctly! |
|
I was looking at
then you can change the input fields to
or
PS you can delete PSS you can use this anywhere that you have a TextField in the app to have the same look |
|
Hi Michael no problems, ok I'll take a look at the example you've mentioned about closing the modals tonight and see if I can understand why that's happening / change to binding for you. the State initial value is good to use as it is straight away setting the values of your state variables so your textfields pre-populate with the data from core data (ready for editing). |
|
Below code will stop the Recipient view being closed when you close your contacts picker.
There is an issue though where the contacts picker will show an blak screen briefly as it loads and disappears. This does seem to be a known issue though, see link. https://stackoverflow.com/questions/60116066/list-of-contacts-from-contacts-app-in-swiftui |
|
This contacts picker seems to work quite well (after you change animated to true within the open func). https://github.com/sramp/SwiftUIContactPicker It also doesn't need any external frameworks. Migth be worth a look Richard |
|
|
|
Tried the first one, and while it does fix it from going away when you hit cancel, it also shows a blank sheet if you select a contact, instead of coming back to an editable form. On the second example, there is also a bit of a weird screen behavior. The picker seems to flash behind the screen when it is being dismissed. |
|
Hi Micheal, Thank you for the credit when you undated github. I was thinking you might want to have a different colour for the required fields you could do that with
then when you want a different colour
and when you want default colour (
|
|
|
|
Hi Michael; I've integrated that second Contact Picker I found into your code and I don't see the weird screen behaviour you mention on dismiss. Did you put EmbeddedContactPicker() at the bottom of the ZStack so that it is at the front? e.g.
|
|
|
|
ok i implemented on top of your code base from last night (copy took about 23:00 UK time) so can share that code if it helps. Im not great with github so not sure if there is a way I can share my updates with you there without overwriting your code. Maybe you know more P.S. my names Richard btw, not Robert :) Thanks |
|
Damn, How'd I get the name wrong, my deepest appology.... Thank you for the correction... If you just want to commit the code in Git.. that would work I have not made changes last night or today. Alternatively drop me an email at michaelrowe01 over at gmail When I tried it, I am getting a weird screen blink. |
|
Hey Michael; No problems at all, don't worry, no apology necessary. You are right actually, there is a screen blink and I've just noted a bigger problem with the contact picker I found - when I load the picker but then cancel, the form behind it disappears completely so that's no good. I think I'm probably reaching the point where I'm just guessing and trying various things (no real change there :-)). I've never implemented a contactPicker before. I suggest maybe creating a new question specifically on the contact picker to see if anyone has any neat code or can work out what the problem is here. If I can help at any further with anything else in your code then please do let me know though. |
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.