Refresh SwiftUI View Programmatically

  Рет қаралды 1,660

Flo writes Code

Flo writes Code

Күн бұрын

Пікірлер: 16
@moiCode429
@moiCode429 8 ай бұрын
thank you bruh, you da best. Theese short videos me like su much ! 🔥
@rahuljamba5846
@rahuljamba5846 8 ай бұрын
Thanks for sharing your knowledge !! keep it up
@marceljaeger
@marceljaeger 8 ай бұрын
Nice video and yeah sometimes you may need to update a view body programatically. But you need to be carefully with changing the identity of a view. When you change an identity of a view. The whole view hierarchy of that view will be created new and that can cause performance issues. Additionally the State properties of Subviews of the HStack will be created new, because the identity changed. So I think a better way may be this: This causes an update of the body of ContentView but not for all Subviews of the HStack if the View values of those Subviews is not different. An other way can be to change the identity of the Color in background without the If statement. struct ContentView: View { @State var value: Bool = true var body: some View { let _ = Self._printChanges() HStack { Button { value.toggle() } label: { Text("Refresh") } //Other sub views } .background { if isTrue { Color.black.opacity(0) }else { Color.black.opacity(0) } } } }
@30guarino
@30guarino 8 ай бұрын
Flo, Was wondering if you can do a video or provide any documentation on how in a chat message view have the last message scroll up above the keyboard when it APPEARS?....Any help will be greatly appreciated
@FloWritesCode
@FloWritesCode 8 ай бұрын
You should be able to use ScrollViewReader to scroll programmatically - I have a video on that API.
@tylerwatt5651
@tylerwatt5651 8 ай бұрын
I'd assume you could use .onAppear in place of the button right?
@FloWritesCode
@FloWritesCode 8 ай бұрын
Yup, depending on your use case.
@markaurelius61
@markaurelius61 8 ай бұрын
You can keep the code tighter by putting the id change after the button: Button("Refresh") { (internalState += 1) } .id(internalState)
@FloWritesCode
@FloWritesCode 8 ай бұрын
Yup, playing around with the position of the id modifier probably makes sense 👍
@0xLarx
@0xLarx 8 ай бұрын
Where are you mate 😂 last video 3 months ago
@FloWritesCode
@FloWritesCode 8 ай бұрын
Been busy with real life stuff! Is there anything you'd like to see on the channel after this break? Thanks for sticking around!
@HomesteadAce
@HomesteadAce 8 ай бұрын
Wasn't the whole point of this view to not use @state? You should have removed it at the end to show that the refresh happens because of the id and not the state change?
@markaurelius61
@markaurelius61 8 ай бұрын
If internalState is not declared with @State, you can't change it in the button event
@SHOLINGER
@SHOLINGER 8 ай бұрын
@HomesteadAce no , the whole point , because the struct is immutable , so @state property wrapper is definitely needed here !!
Snap to Scroll in SwiftUI (iOS 17+)
3:44
Flo writes Code
Рет қаралды 1,1 М.
Stop using GeometryReader in SwiftUI
4:27
Flo writes Code
Рет қаралды 6 М.
I tricked MrBeast into giving me his channel
00:58
Jesser
Рет қаралды 29 МЛН
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 12 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 11 МЛН
The BEST Way to Build an App
6:29
Flo writes Code
Рет қаралды 1,4 М.
SwiftUI @Binding in 4 Minutes!!
4:14
Tech With Talal
Рет қаралды 44
Horizontal Layouts on macOS (SwiftUI)
5:04
Flo writes Code
Рет қаралды 760
VIM: A new SwiftUI Architecture for iOS 17
3:37
Flo writes Code
Рет қаралды 4,6 М.
WidgetKit Masterclass 2024
2:29:03
Flo writes Code
Рет қаралды 2,4 М.
How to Become an iOS Developer in 2024 (If I had to start over)
5:06
React Native New Update Play Around
14:37
Simply React Native
Рет қаралды 665
Read ScrollPosition & Change Starting Point in iOS 18
5:06
Flo writes Code
Рет қаралды 953
I tricked MrBeast into giving me his channel
00:58
Jesser
Рет қаралды 29 МЛН