Comments (6)
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.
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.
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.
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.
No, that's all there is to it.
from splitview.
Yep - had to swap between 2 diff splitters in the .fraction() modifier - working now - thanks !
from splitview.
Related Issues (20)
- Issue When Dragging a Splitter Outside the Parent Window on MacOS HOT 4
- Instantiating from a simpler format? HOT 1
- Change cursor on Mac when inside splitter HOT 4
- Set SplitView Constraints Maximum HOT 1
- Set SplitView Constraints by absolute number HOT 1
- Nested views ad infinitum HOT 3
- Sticky buttons in secondary views or on press repeat HOT 4
- Feature: minimum split size HOT 8
- Bug: splitter line should be invisible when hidden HOT 2
- divider's visual bug HOT 11
- Option to offset views instead of changing frame size HOT 5
- Breakpoints & animations HOT 1
- Hidden view still visible partly HOT 4
- Custom splitter using drag-to-hide
- Setting fraction programmatically (after the split view is shown already) HOT 2
- CustomSplitter disappears when constraints is set HOT 4
- Bug when hiding splitview while using minimum fractions HOT 3
- Default splitter HOT 2
- Fraction animation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from splitview.