feat(image): 이미지 선택 후 크롭 편집 흐름을 적용한다
This commit is contained in:
@@ -14,6 +14,10 @@ struct LiveRoomCreateView: View {
|
||||
@StateObject var viewModel = LiveRoomCreateViewModel()
|
||||
|
||||
@State private var isShowPhotoPicker = false
|
||||
@State private var selectedPickedImage: UIImage?
|
||||
@State private var cropSourceImage: UIImage?
|
||||
@State private var isShowImageCropper = false
|
||||
@State private var isImageLoading = false
|
||||
@State private var isShowSelectTagView = false
|
||||
@State private var isShowSelectDateView = false
|
||||
@State private var isShowSelectTimeView = false
|
||||
@@ -233,14 +237,6 @@ struct LiveRoomCreateView: View {
|
||||
SelectTimeView()
|
||||
}
|
||||
|
||||
if isShowPhotoPicker {
|
||||
ImagePicker(
|
||||
isShowing: $isShowPhotoPicker,
|
||||
selectedImage: $viewModel.coverImage,
|
||||
sourceType: .photoLibrary
|
||||
)
|
||||
}
|
||||
|
||||
GeometryReader { proxy in
|
||||
VStack {
|
||||
Spacer()
|
||||
@@ -254,6 +250,24 @@ struct LiveRoomCreateView: View {
|
||||
}
|
||||
}
|
||||
.edgesIgnoringSafeArea(.bottom)
|
||||
|
||||
if isShowPhotoPicker {
|
||||
ImagePicker(
|
||||
isShowing: $isShowPhotoPicker,
|
||||
selectedImage: $selectedPickedImage,
|
||||
sourceType: .photoLibrary
|
||||
)
|
||||
}
|
||||
|
||||
if isImageLoading {
|
||||
ZStack {
|
||||
Color.black.opacity(0.45)
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
||||
}
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
hideKeyboard()
|
||||
@@ -266,6 +280,45 @@ struct LiveRoomCreateView: View {
|
||||
viewModel.timeSettingMode = timeSettingMode
|
||||
viewModel.getAllMenuPreset()
|
||||
}
|
||||
.onChange(of: selectedPickedImage, perform: { newImage in
|
||||
guard let newImage else {
|
||||
return
|
||||
}
|
||||
|
||||
isImageLoading = true
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
let normalizedImage = newImage.normalizedForCrop()
|
||||
DispatchQueue.main.async {
|
||||
isImageLoading = false
|
||||
selectedPickedImage = nil
|
||||
cropSourceImage = normalizedImage
|
||||
isShowImageCropper = true
|
||||
}
|
||||
}
|
||||
})
|
||||
.onDisappear {
|
||||
isImageLoading = false
|
||||
}
|
||||
.sheet(isPresented: $isShowImageCropper, onDismiss: {
|
||||
cropSourceImage = nil
|
||||
}) {
|
||||
if let cropSourceImage {
|
||||
ImageCropEditorView(
|
||||
image: cropSourceImage,
|
||||
aspectPolicy: .free,
|
||||
onCancel: {
|
||||
isShowImageCropper = false
|
||||
},
|
||||
onComplete: { croppedImage in
|
||||
viewModel.coverImage = croppedImage
|
||||
viewModel.coverImageUrl = nil
|
||||
viewModel.coverImagePath = nil
|
||||
isShowImageCropper = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
||||
Reference in New Issue
Block a user