Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State Management similar to SwiftUI #11

Open
Chandram-Dutta opened this issue Feb 12, 2025 · 2 comments
Open

State Management similar to SwiftUI #11

Chandram-Dutta opened this issue Feb 12, 2025 · 2 comments

Comments

@Chandram-Dutta
Copy link

right now, things like TextField and NavigationSplitView depends on TextController and ValueNotifier. ik this is a rewrite of flutter in swift, but wouldn't it be better to replace them with something like @State or Observation Framework...

@xtyxtyx
Copy link
Contributor

xtyxtyx commented Feb 12, 2025

Totally agree with you that something like @State is absolutely better.

Currently things like "TextController" are intentionally kept to make it easier to port Flutter framework code to Shaft.

And there is some challenges in adopting @State. As far as I know the SwiftUI @State is implemented with some internal APIs and memory hacks that can be complex to replicate.

I'm actively exploring potential workarounds for this. And any suggestions would be greatly appreciated.

@n7trd
Copy link

n7trd commented Feb 12, 2025

And any suggestions would be greatly appreciated.

This could be interesting, especially the state management part:
https://git.aparoksha.dev/aparoksha/meta/src/branch/main

// State management example from the site:

struct SearchView: View {

    @State private var count = 0

    var view: Body {
        Button(icon: .minus) {
            count -= 1
        }
        Text("\(count)")
        Button(icon: .plus) {
            count += 1
        }
    }

}

It's part of the Aparoksha project for cross-platform apps that uses native widgets, but it could be beneficial to share code that is important regardless of how widgets are rendered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants