Skip to content

Commit

Permalink
Added documentation for interactableImage file (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
bellatrick authored Jan 11, 2024
1 parent 6c00d78 commit 941e2da
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Sources/Picture/Public/InteractableImage.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@

// InteractableImage.swift

import SwiftUI

/**
The `InteractableImage` view allows users to interact with an image. It supports the following features:

- Pinch gestures to zoom in and out on the image
- Drag gestures to pan the image
- A reset button that restores the image to its original size and position
- Accessibility actions to allow VoiceOver users to zoom in and out

- Note: The view manages its state, including zoom level and offset, using the `InteractableImageViewModel` object.
Access this object through the `viewModel` property.
*/

public struct InteractableImage: View {
@ObservedObject private var viewModel: InteractableImageViewModel

/**
Gesture for magnifying the image.
- Parameters:
- value: The magnification value.
*/
private var magnificationGesture: some Gesture {
MagnifyGesture()
.onChanged { value in
Expand All @@ -15,6 +35,11 @@ public struct InteractableImage: View {
}
}

/**
Gesture for dragging and repositioning the image.
- Parameters:
- value: The translation value.
*/
private var dragGesture: some Gesture {
DragGesture()
.onChanged { value in
Expand All @@ -25,12 +50,21 @@ public struct InteractableImage: View {
}
}

/**
Initializes the 'InteractableImage' view with a specified picture source.
- Parameters:
- source: The source of the picture (local file or remote URL).
*/
public init(source: PictureSource) {
self._viewModel = ObservedObject(
initialValue: InteractableImageViewModel(source: source)
)
}

/**
Body of the 'InteractableImage' view, handling image display, zoom, and gestures.
- Returns: A SwiftUI `View` representing the interactive image.
*/
public var body: some View {
if let image = viewModel.image {
ZStack {
Expand Down

0 comments on commit 941e2da

Please sign in to comment.