Improvements to scroll views in SwiftUI – this allows for expanding beyond the screen port.
You can define which axis it will scroll – horizontal or vertical. It will resolve safe area to show information within its content offset.
Margins and safe area
- You can add hMargin to a .safeAreaPadding( <direction>, hMargin) – note this does not use a dot prefix.
- ScrollView resolves safe area into the margins to show its content, for things like scroll indicators, etc.
- .contentMargins API allows you to control the content separately from the safe area.
- By default you get a standard declaration rate for target content offset when lifting your finger. Now you can add .scrollTargetBehavior() modifier to do things like paging scrolls, or .viewAligned to align to other views, via the Scroll target. .scrollTargetLayout()
- Using LazyStacks require that you use scrollTargetLayout() modifier to ensure that it scrolls to the right place.
- You can also confirm your own custom behavior ScrollTargetBehavior with the updateTarget method.
Target and Positions
- New API containerRelativeFrame modifier allows you to take on the size of the container, without having to use a GeometryReader. This would be good for my card app.
- You can remove .scrollIndicator(.hidden) – which has been around. Default behavior will be to hide the indicators, but to allow them to show when mouse is connected. But you can add .never to force it to hide the scroll indicators. So you can add views with additional “Paddle”s to provide buttons for platforms to show scroll behavior. I really don’t like that you can force scroll indicators off. I think this keeps hiding functionality that a user needs to have. I can see this being used by bad actors.
Scroll Transitions
- To visually alter a based on where it is in the hierarchy – this are achieved with ScrollTransitions
- You can define actions based on phase
- This uses new protocol called VisualEffect:
- Scale
- Rotation
- Offset
- Are all visual effects
- You cannot use this for things that change the overall size of the content