Akash
02/13/2024, 1:30 PM*let* scannerViewController = ImageScannerController(delegate: *self*)
scannerViewController.modalPresentationStyle = .fullScreen
self.present(scannerViewController, animated: *true*)
// for dismiss
self.dismiss(animated: *true*, completion: *nil*)
I am using kotlin multiplatformNicoLourenco
02/13/2024, 3:34 PMself.dismiss
will try to dismiss your current view (self), not the scannerViewController
Akash
02/13/2024, 3:38 PMNicoLourenco
02/13/2024, 3:41 PMImageScannerController
?Akash
02/13/2024, 4:00 PMAkash
02/13/2024, 4:00 PMAkash
02/13/2024, 4:05 PMstruct ComposeView : UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
let iosPlatformInterfaceImpl = IosPlatformInterfaceImpl()
let mainViewController = MainViewControllerKt.MainViewController(platformFeatureInterface: iosPlatformInterfaceImpl)
iosPlatformInterfaceImpl.viewController = mainViewController // Pass the reference to the view controller
return mainViewController
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
struct ContentView: View {
var body: some View {
ComposeView()
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler
}
}
class IosPlatformInterfaceImpl : NSObject, CommonResourcesPlatformFeatureInterface, ImageScannerControllerDelegate,ScannerCallBack {
func result() {
viewController?.dismiss(animated: true){
self.onCompletionn?(self.randomArrayValue())
}
}
weak var viewController: UIViewController? // Reference to the view controller
var onCompletionn: ((NSMutableArray) -> Void)?
func openScannerAndGetScannedImages(onCompletion: @escaping (NSMutableArray) -> Void) {
self.onCompletionn = onCompletion
scanImage(completion: onCompletion)
}
func openCamera(onCompletion: @escaping (String) -> Void) {
print("hi openCamera")
}
func scanImage(completion: @escaping (NSMutableArray) -> Void) {
guard let viewController = viewController else { return }
// let scannerViewController = DigioViewController()
// scannerViewController.result = self
let scannerViewController = ImageScannerController(delegate: self)
scannerViewController.modalPresentationStyle = .fullScreen
if #available(iOS 13.0, *) {
scannerViewController.navigationBar.tintColor = .label
} else {
scannerViewController.navigationBar.tintColor = .black
}
self.onCompletionn = completion
viewController.present(scannerViewController, animated: true)
}
func imageScannerController(_ scanner: ImageScannerController, didFinishScanningWithResults results: ImageScannerResults) {
print("imageScannerController didFinishScanningWithResults")
// scanner.dismiss(animated: true, completion: nil)
// scanner.navigationController?.dismiss(animated: true)
scanner.dismiss(animated: false){
self.onCompletionn?(self.randomArrayValue())
}
// self.onCompletionn?(randomArrayValue())
}
}
Akash
02/13/2024, 4:05 PMAkash
02/14/2024, 8:25 AMAkash
02/14/2024, 8:26 AM