Giter Club home page Giter Club logo

Comments (6)

stevengharris avatar stevengharris commented on June 5, 2024

Glad it's useful to you.

In your example, the snippetFraction and templateFraction should be retrieved from UserDefaults.standard based on the keys you supplied, so I'm not sure what's going on. If you want to use something other than UserDefaults.standard, you can use the more elaborate initializer for FractionHolder, like the usingUserDefaults function does:

public static func usingUserDefaults(_ fraction: CGFloat? = nil, key: String) -> FractionHolder {
    FractionHolder(
        fraction,
        getter: { UserDefaults.standard.value(forKey: key) as? CGFloat ?? fraction ?? 0.5 },
        setter: { fraction in UserDefaults.standard.set(fraction, forKey: key) }
    )
}

and just supply your own closures for getter and setter. In your case, if the fraction still comes up, not the new value that gets set when drag ends, you could try debugging by putting a breakpoint or print statement in the setter and/or getter closure.

from splitview.

pkasson avatar pkasson commented on June 5, 2024

I was not sure if you needed to use the keys you showed in the example ("myFraction"). So, I understand that it can't find something not stored in UserDefaults, how is the last state stored there ?

from splitview.

stevengharris avatar stevengharris commented on June 5, 2024

Yes, the idea is to use keys that make sense in the context of your app. For fraction, the Split view updates its CGFloat value whenever dragging stops, in onEnded using fraction.value = privateFraction:

    private func drag(in size: CGSize) -> some Gesture {
        return DragGesture()
            .onChanged { gesture in
                unhide(in: size)    // Unhide if the splitter is hidden, but resetting privateFraction first
                privateFraction = fraction(for: gesture, in: size)
                onDrag?(privateFraction)
                previousPosition = layout.isHorizontal ? privateFraction * size.width : privateFraction * size.height
            }
            .onEnded { gesture in
                previousPosition = nil
                fraction.value = privateFraction
            }
    }

from splitview.

pkasson avatar pkasson commented on June 5, 2024

So with my code example, then your framework would have saved using my key "snippetFraction" or is there a step I am missing ?

from splitview.

stevengharris avatar stevengharris commented on June 5, 2024

No, that's all there is to it.

from splitview.

pkasson avatar pkasson commented on June 5, 2024

Yep - had to swap between 2 diff splitters in the .fraction() modifier - working now - thanks !

from splitview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.