Scroll - Tai-Kimura/SwiftJsonUI GitHub Wiki

Scroll

class: SJUIScrollView inherites: UIScrollView

Platform Support

  • UIKit: Full support (All attributes available)
  • SwiftUI: Full support (Maps to ScrollView with equivalent functionality)
  • Jetpack Compose: Full support (Maps to scrollable modifiers)
  • Android XML: Maps to ScrollView (vertical) or HorizontalScrollView (horizontal)

Attributes for Scroll

attribute name UIKit SwiftUI Compose XML type in json details remarks
showsHorizontalScrollIndicator boolean scrollview.showsHorizontalScrollIndicator. Default is false
showsVerticalScrollIndicator boolean scrollview.showsVerticalScrollIndicator. Default is false
maxZoom float scrollview.maximumZoomScale
minZoom float scrollview.minimumZoomScale
paging boolean scrollview.isPagingEnabled iOS 17+ in static mode
bounces boolean scrollview.bounces Comment only in static
scrollEnabled boolean scrollview.scrollEnabled
contentInsetAdjustmentBehavior string Controls safe area insets: automatic, always, never, scrollableAxes 7.0.0-beta: Improved SafeArea
onclick string Tap gesture selector
contentSize array Direct content size [width, height] UIKit only
contentOffset array Initial content offset [x, y] UIKit only
decelerationRate string Deceleration rate: normal, fast UIKit only
indicatorStyle string Scroll indicator style UIKit only
keyboardDismissMode string Keyboard dismiss mode: none, onDrag, interactive
scrollsToTop boolean Scroll to top on status bar tap UIKit only

Properties for Scroll

Static Properties

open class var viewClass: SJUIScrollView.Type

This property will be used to decide which class to inflate with createFromJSON method. You should define the view's class on this property when you create classes inheriting from SJUIScrollView.

Inherited Properties

SJUIScrollView inherits all properties from UIScrollView and SJUIView, including:

  • Content size and offset management
  • Zoom scale properties (maximumZoomScale, minimumZoomScale)
  • Scroll indicators and behavior settings
  • Touch and gesture handling from SJUIView
  • Layout constraint management
  • Delegate support for UIScrollViewDelegate

Functions for Scroll

Static Methods

public class func createFromJSON(attr: JSON, target: Any, views: inout [String: UIView]) -> SJUIScrollView

Factory method called when the scroll view is created from JSON file. Override this method when you create classes inheriting from SJUIScrollView class.

Delegate Support

SJUIScrollView automatically sets the target as delegate if the target conforms to UIScrollViewDelegate. This enables handling of scroll events such as:

  • scrollViewDidScroll(_:)
  • scrollViewDidEndScrollingAnimation(_:)
  • viewForZooming(in:) for zoom functionality
  • scrollViewDidZoom(_:)

Event Handling

SJUIScrollView supports touch events through:

  • The onclick attribute for tap gesture recognition
  • Integration with SJUIView's touch handling system
  • Full UIScrollView gesture recognition (pan, pinch, etc.)
  • Custom corner radius support through JSON attributes

Inherited Methods

SJUIScrollView inherits all methods from UIScrollView and SJUIView, including:

  • Scroll position management (setContentOffset, scrollRectToVisible, etc.)
  • Zoom functionality (setZoomScale, zoom(to:animated:), etc.)
  • Touch and gesture handling from SJUIView
  • Layout constraint management
  • Content size calculation and management

Usage with SafeAreaView (7.0.0-beta)

Recommended Pattern

When using ScrollView inside SafeAreaView, set contentInsetAdjustmentBehavior to "never" to avoid double safe area insets:

{
  "type": "SafeAreaView",
  "child": [
    {
      "type": "Scroll",
      "contentInsetAdjustmentBehavior": "never",
      "child": [
        {
          "type": "View",
          "orientation": "vertical",
          "padding": 16,
          "child": [
            {
              "type": "Label",
              "text": "Content properly respects safe area"
            }
          ]
        }
      ]
    }
  ]
}

Full-Screen ScrollView

For edge-to-edge scrollable content that extends under system UI:

{
  "type": "View",
  "child": [
    {
      "type": "Scroll",
      "contentInsetAdjustmentBehavior": "automatic",
      "child": [
        {
          "type": "Image",
          "image": "full_screen_background",
          "contentMode": "AspectFill"
        }
      ]
    }
  ]
}