Skip to content

Commit

Permalink
feat: user can add custom strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Marcato authored and kuamanet committed Nov 18, 2022
1 parent 7eccd73 commit f7a09f6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 30 deletions.
32 changes: 22 additions & 10 deletions Sources/ImagePickerModule/MediasPickerButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,35 @@ import SwiftUI

@State private var showCameraMediaPicker: Bool = false
@State private var showLibraryMediaPicker: Bool = false
var selectPhotoOrVideoText: String
var takePhotoOrVideoText: String
var grantCameraAndMicrophoneText: String
var grantCameraAndMicrophoneTextMessage: String
var settingsText: String
@State private var showMicrophoneAndCameraAccessRequiredAlert: Bool = false

public init(
selectedImages: Binding<[UIImage]>,
selectedVideos: Binding<[URL]>,
noCameraAccessStrategy: NoPermissionsStrategy = NoPermissionsStrategy.showToSettings,
@ViewBuilder label: @escaping () -> Content,
allowsEditing: Bool = false
allowsEditing: Bool = false,
selectPhotoOrVideoText: String = "Selezionare le foto o i video dalla libreria",
takePhotoOrVideoText: String = "Scattare una foto o registrare un video con la fotocamera",
grantCameraAndMicrophoneText: String = "È necessario l'accesso alla telecamera e al microfono",
grantCameraAndMicrophoneTextMessage: String = "L'accesso alla fotocamera e al microfono può essere concesso nelle impostazioni di sistema di questa applicazione.",
settingsText: String = "Impostazioni"
) {
_selectedImages = selectedImages
_selectedVideos = selectedVideos
self.noCameraAccessStrategy = noCameraAccessStrategy
self.label = label()
self.allowsEditing = allowsEditing
self.selectPhotoOrVideoText = selectPhotoOrVideoText
self.takePhotoOrVideoText = takePhotoOrVideoText
self.grantCameraAndMicrophoneText = grantCameraAndMicrophoneText
self.grantCameraAndMicrophoneTextMessage = grantCameraAndMicrophoneTextMessage
self.settingsText = settingsText
}

public var body: some View {
Expand All @@ -45,8 +60,7 @@ import SwiftUI
Button(
action: { self.showLibraryMediaPicker = true },
label: {
Label(NSLocalizedString("Selezionare le foto o i video dalla libreria", comment: ""),
systemImage: "folder")
Label(self.selectPhotoOrVideoText, systemImage: "folder")
}
)

Expand All @@ -56,8 +70,7 @@ import SwiftUI
Button(
action: { self.showCameraMediaPicker = true },
label: {
Label(NSLocalizedString("Scattare una foto o registrare un video con la fotocamera", comment: ""),
systemImage: "camera")
Label(self.takePhotoOrVideoText, systemImage: "camera")
}
)

Expand All @@ -67,8 +80,7 @@ import SwiftUI
action: { self.showMicrophoneAndCameraAccessRequiredAlert = true
},
label: {
Label(NSLocalizedString("Scattare una foto o registrare un video con la fotocamera", comment: ""),
systemImage: "camera")
Label(self.takePhotoOrVideoText, systemImage: "camera")
}
)
}
Expand Down Expand Up @@ -100,9 +112,9 @@ import SwiftUI

Text("").alert(isPresented: self.$showMicrophoneAndCameraAccessRequiredAlert) {
Alert(
title: Text(NSLocalizedString("È necessario l'accesso alla telecamera e al microfono", comment: "")),
message: Text(NSLocalizedString("L'accesso alla fotocamera e al microfono può essere concesso nelle impostazioni di sistema di questa applicazione.", comment: "")),
primaryButton: Alert.Button.default(Text(NSLocalizedString("Impostazioni", comment: ""))) {
title: Text(self.grantCameraAndMicrophoneText),
message: Text(self.grantCameraAndMicrophoneTextMessage),
primaryButton: Alert.Button.default(Text(self.settingsText)) {
guard let settingsURL = URL(string: UIApplication.openSettingsURLString) else { return }
UIApplication.shared.open(settingsURL, options: [:], completionHandler: nil)
},
Expand Down
52 changes: 32 additions & 20 deletions Sources/ImagePickerModule/SingleMediaPickerButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,29 @@ import SwiftUI
@State private var showSelectedImageOrVideo: Bool = false
@State private var showCameraAndMicrophoneAccessRequiredAlert: Bool = false

var selectPhotoOrVideoText: String
var takePhotoOrVideoText: String
var grantCameraAndMicrophoneText: String
var showCurrentPhotoOrVideoText: String
var deleteCurrentPhotoOrVideoText: String
var grantCameraAndMicrophoneTextMessage: String
var settingsText: String

init(
selectedImage: Binding<UIImage?>,
selectedVideo: Binding<URL?>,
noCameraAccessStrategy: NoPermissionsStrategy = NoPermissionsStrategy.showToSettings,
label: @escaping () -> Content,
onDelete: (() -> Void)? = nil,
defaultImageContent: (() -> DefaultImageContent)?,
allowsEditing: Bool = false
allowsEditing: Bool = false,
selectPhotoOrVideoText: String = "Selezionare la foto o il video dalla libreria",
takePhotoOrVideoText: String = "Scattare una foto o video con la fotocamera",
showCurrentPhotoOrVideoText: String = "Mostra l'immagine o video corrente",
deleteCurrentPhotoOrVideoText: String = "Rimuovere l'immagine o video corrente",
grantCameraAndMicrophoneText: String = "È necessario l'accesso alla telecamera e al microfono",
grantCameraAndMicrophoneTextMessage: String = "L'accesso alla fotocamera e al microfono può essere concesso nelle impostazioni di sistema di questa applicazione.",
settingsText: String = "Impostazioni"
) {
_selectedImage = selectedImage
_selectedVideo = selectedVideo
Expand All @@ -47,6 +62,13 @@ import SwiftUI
self.label = label()
self.defaultImageContent = defaultImageContent
self.allowsEditing = allowsEditing
self.selectPhotoOrVideoText = selectPhotoOrVideoText
self.takePhotoOrVideoText = takePhotoOrVideoText
self.showCurrentPhotoOrVideoText = showCurrentPhotoOrVideoText
self.deleteCurrentPhotoOrVideoText = deleteCurrentPhotoOrVideoText
self.grantCameraAndMicrophoneText = grantCameraAndMicrophoneText
self.grantCameraAndMicrophoneTextMessage = grantCameraAndMicrophoneTextMessage
self.settingsText = settingsText
}

public var body: some View {
Expand All @@ -56,8 +78,7 @@ import SwiftUI
Button(
action: { self.showLibraryMediaPicker = true },
label: {
Label(NSLocalizedString("Selezionare la foto o video dalla libreria", comment: ""),
systemImage: "folder")
Label(self.selectPhotoOrVideoText, systemImage: "folder")
}
)

Expand All @@ -67,8 +88,7 @@ import SwiftUI
Button(
action: { self.showCameraMediaPicker = true },
label: {
Label(NSLocalizedString("Scattare una foto o video con la fotocamera", comment: ""),
systemImage: "camera")
Label(self.takePhotoOrVideoText, systemImage: "camera")
}
)

Expand All @@ -79,10 +99,7 @@ import SwiftUI
self.showCameraAndMicrophoneAccessRequiredAlert = true
},
label: {
Label(
NSLocalizedString("Scattare una foto o video con la fotocamera", comment: ""),
systemImage: "camera"
)
Label(self.takePhotoOrVideoText, systemImage: "camera")
}
)
}
Expand All @@ -92,10 +109,7 @@ import SwiftUI
Button(
action: { self.showSelectedImageOrVideo = true },
label: {
Label(
NSLocalizedString("Mostra l'immagine o video corrente", comment: ""),
systemImage: "arrow.up.backward.and.arrow.down.forward"
)
Label(self.showCurrentPhotoOrVideoText, systemImage: "arrow.up.backward.and.arrow.down.forward")
}
)
}
Expand All @@ -108,10 +122,8 @@ import SwiftUI
self.selectedVideo = nil
},
label: {
Label(
NSLocalizedString("Rimuovere l'immagine o video corrente", comment: ""),
systemImage: "xmark"
)
Label(self.deleteCurrentPhotoOrVideoText,
systemImage: "xmark")
}
)
}
Expand Down Expand Up @@ -165,9 +177,9 @@ import SwiftUI

Text("").alert(isPresented: self.$showCameraAndMicrophoneAccessRequiredAlert) {
Alert(
title: Text(NSLocalizedString("È necessario l'accesso alla telecamera", comment: "")),
message: Text(NSLocalizedString("L'accesso alla fotocamera può essere concesso nelle impostazioni di sistema di questa applicazione.", comment: "")),
primaryButton: Alert.Button.default(Text(NSLocalizedString("Impostazioni", comment: ""))) {
title: Text(self.grantCameraAndMicrophoneText),
message: Text(self.grantCameraAndMicrophoneTextMessage),
primaryButton: Alert.Button.default(Text(self.settingsText)) {
guard let settingsURL = URL(string: UIApplication.openSettingsURLString) else { return }
UIApplication.shared.open(settingsURL, options: [:], completionHandler: nil)
},
Expand Down

0 comments on commit f7a09f6

Please sign in to comment.