Skip to content

Commit dd63feb

Browse files
committed
Fixed camera not opening from modal on iOS
1 parent b0021c9 commit dd63feb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/camera-plus.ios.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export class MySwifty extends SwiftyCamViewController {
236236
}
237237

238238
public closePicker() {
239-
rootVC().dismissViewControllerAnimatedCompletion(true, () => {
239+
this.getParentViewController().dismissViewControllerAnimatedCompletion(true, () => {
240240
this.pickerDelegate = null;
241241
});
242242
}
@@ -418,6 +418,7 @@ export class MySwifty extends SwiftyCamViewController {
418418
this._imageConfirmBg.addSubview(retakeBtn);
419419
this._imageConfirmBg.addSubview(saveBtn);
420420
this.view.addSubview(this._imageConfirmBg);
421+
this._owner.get().sendEvent(CameraPlus.confirmScreenShownEvent);
421422
} else {
422423
// no confirmation - just save
423424
this.savePhoto();
@@ -429,6 +430,7 @@ export class MySwifty extends SwiftyCamViewController {
429430
if (this._imageConfirmBg) {
430431
this._imageConfirmBg.removeFromSuperview();
431432
this._imageConfirmBg = null;
433+
this._owner.get().sendEvent(CameraPlus.confirmScreenDismissedEvent);
432434
}
433435
}
434436

@@ -450,6 +452,15 @@ export class MySwifty extends SwiftyCamViewController {
450452
return UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera);
451453
}
452454

455+
public getParentViewController() {
456+
var responder: UIResponder = this.view;
457+
do {
458+
responder = responder.nextResponder;
459+
} while (responder && !(NSStringFromClass(responder.class()) === 'UIViewControllerImpl'));
460+
461+
return <UIViewController>responder;
462+
}
463+
453464
public chooseFromLibrary(options?: IChooseOptions): Promise<any> {
454465
return new Promise((resolve, reject) => {
455466
this._pickerDelegate = null;
@@ -493,7 +504,7 @@ export class MySwifty extends SwiftyCamViewController {
493504

494505
imagePickerController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext;
495506

496-
rootVC().presentViewControllerAnimatedCompletion(imagePickerController, true, null);
507+
this.getParentViewController().presentViewControllerAnimatedCompletion(imagePickerController, true, null);
497508
});
498509
}
499510

@@ -733,11 +744,6 @@ export class CameraPlus extends CameraPlusBase {
733744
}
734745
}
735746

736-
const rootVC = function() {
737-
let appWindow = UIApplication.sharedApplication.keyWindow;
738-
return appWindow.rootViewController;
739-
};
740-
741747
const createButton = function(
742748
target: any,
743749
frame: CGRect,

0 commit comments

Comments
 (0)