-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(ios): introduce PhotoCrop reducer to start working on crop tool
- Loading branch information
1 parent
527c5da
commit 98f2e47
Showing
3 changed files
with
115 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import ComposableArchitecture | ||
import FeatureActionLibrary | ||
import SwiftUI | ||
|
||
@Reducer | ||
public struct PhotoCrop: Reducer { | ||
@ObservableState | ||
public struct State: Equatable { | ||
public var image: UIImage | ||
public var offset: CGSize = .zero | ||
|
||
public init(image: UIImage) { | ||
self.image = image | ||
} | ||
} | ||
|
||
public enum Action: ViewAction, FeatureAction, BindableAction { | ||
@CasePathable public enum View { | ||
case didTapDone | ||
} | ||
|
||
@CasePathable public enum Delegate { | ||
case didFinishCropping(UIImage) | ||
} | ||
|
||
@CasePathable public enum Internal { | ||
case doNothing | ||
} | ||
|
||
case view(View) | ||
case delegate(Delegate) | ||
case `internal`(Internal) | ||
case binding(BindingAction<State>) | ||
} | ||
|
||
public init() {} | ||
|
||
public var body: some ReducerOf<Self> { | ||
BindingReducer() | ||
|
||
Reduce<State, Action> { state, action in | ||
switch action { | ||
case let .view(viewAction): | ||
switch viewAction { | ||
case .didTapDone: | ||
return .none | ||
} | ||
|
||
case let .internal(internalAction): | ||
switch internalAction { | ||
case .doNothing: | ||
return .none | ||
} | ||
|
||
case .delegate, .binding: | ||
return .none | ||
} | ||
} | ||
} | ||
} | ||
|
||
@ViewAction(for: PhotoCrop.self) | ||
public struct PhotoCropView: View { | ||
@Bindable public var store: StoreOf<PhotoCrop> | ||
|
||
public init(store: StoreOf<PhotoCrop>) { | ||
self.store = store | ||
} | ||
|
||
public var body: some View { | ||
ZStack { | ||
Image(uiImage: store.image) | ||
.resizable() | ||
.scaledToFit() | ||
} | ||
} | ||
} |