Skip to content

Commit f6c1c9e

Browse files
raju-muliyashiyaRaju
authored andcommitted
Code format
1 parent ae517b5 commit f6c1c9e

File tree

2 files changed

+85
-77
lines changed

2 files changed

+85
-77
lines changed

packages/image_picker/image_picker_ios/example/ios/RunnerTests/ImagePickerPluginTests.m

Lines changed: 68 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,11 @@ - (void)testPickMultiVideoWithoutLimit {
701701
XCTAssertEqual(plugin.callContext.maxItemCount, 0);
702702
}
703703

704-
#pragma mark - Test immediate picker close detection
705-
706704
- (void)testUIImagePickerImmediateCloseReturnsEmptyArray {
707705
FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init];
708-
706+
709707
XCTestExpectation *resultExpectation = [self expectationWithDescription:@"result"];
710-
708+
711709
FLTImagePickerMethodCallContext *context = [[FLTImagePickerMethodCallContext alloc]
712710
initWithResult:^void(NSArray<NSString *> *paths, FlutterError *error) {
713711
if (paths == nil || paths.count == 0) {
@@ -719,46 +717,47 @@ - (void)testUIImagePickerImmediateCloseReturnsEmptyArray {
719717
context.maxSize = [[FLTMaxSize alloc] init];
720718
context.maxItemCount = 1;
721719
context.requestFullMetadata = NO;
722-
720+
723721
plugin.callContext = context;
724-
722+
725723
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
726724
UIView *controllerView = controller.view;
727-
725+
728726
UIView *observerView = [[UIView alloc] init];
729727
[controllerView addSubview:observerView];
730-
728+
731729
void (^removeCallback)(void) = ^{
732-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
733-
if (plugin && plugin.callContext == context && !plugin.isProcessingSelection) {
734-
[plugin sendCallResultWithSavedPathList:nil];
735-
}
736-
});
730+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)),
731+
dispatch_get_main_queue(), ^{
732+
if (plugin && plugin.callContext == context && !plugin.isProcessingSelection) {
733+
[plugin sendCallResultWithSavedPathList:nil];
734+
}
735+
});
737736
};
738-
737+
739738
UIWindow *testWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
740739
testWindow.hidden = NO;
741740
[testWindow addSubview:controllerView];
742-
741+
743742
[testWindow setNeedsLayout];
744743
[testWindow layoutIfNeeded];
745-
744+
746745
[controllerView removeFromSuperview];
747-
746+
748747
removeCallback();
749-
748+
750749
[self waitForExpectationsWithTimeout:1.0 handler:nil];
751750
}
752751

753752
- (void)testPHPickerImmediateCloseReturnsEmptyArray API_AVAILABLE(ios(14)) {
754753
id photoLibrary = OCMClassMock([PHPhotoLibrary class]);
755754
OCMStub(ClassMethod([photoLibrary authorizationStatus]))
756755
.andReturn(PHAuthorizationStatusAuthorized);
757-
756+
758757
FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init];
759-
758+
760759
XCTestExpectation *resultExpectation = [self expectationWithDescription:@"result"];
761-
760+
762761
[plugin pickMultiImageWithMaxSize:[[FLTMaxSize alloc] init]
763762
quality:nil
764763
fullMetadata:NO
@@ -770,23 +769,23 @@ - (void)testPHPickerImmediateCloseReturnsEmptyArray API_AVAILABLE(ios(14)) {
770769
XCTAssertNil(error);
771770
[resultExpectation fulfill];
772771
}];
773-
772+
774773
id mockPresentationController = OCMClassMock([UIPresentationController class]);
775774
[plugin presentationControllerDidDismiss:mockPresentationController];
776-
775+
777776
[self waitForExpectationsWithTimeout:1.0 handler:nil];
778777
}
779778

780779
- (void)testObserverDoesNotInterfereWhenProcessingSelection API_AVAILABLE(ios(14)) {
781780
id photoLibrary = OCMClassMock([PHPhotoLibrary class]);
782781
OCMStub(ClassMethod([photoLibrary authorizationStatus]))
783782
.andReturn(PHAuthorizationStatusAuthorized);
784-
783+
785784
FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init];
786-
785+
787786
XCTestExpectation *resultExpectation = [self expectationWithDescription:@"result"];
788787
__block BOOL emptyResultReceived = NO;
789-
788+
790789
[plugin pickMultiImageWithMaxSize:[[FLTMaxSize alloc] init]
791790
quality:nil
792791
fullMetadata:NO
@@ -800,38 +799,40 @@ - (void)testObserverDoesNotInterfereWhenProcessingSelection API_AVAILABLE(ios(14
800799
emptyResultReceived = YES;
801800
}
802801
}];
803-
802+
804803
NSURL *tiffURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"tiffImage"
805804
withExtension:@"tiff"];
806805
NSItemProvider *tiffItemProvider = [[NSItemProvider alloc] initWithContentsOfURL:tiffURL];
807806
PHPickerResult *tiffResult = OCMClassMock([PHPickerResult class]);
808807
OCMStub([tiffResult itemProvider]).andReturn(tiffItemProvider);
809-
808+
810809
id mockPickerViewController = OCMClassMock([PHPickerViewController class]);
811-
810+
812811
[plugin picker:mockPickerViewController didFinishPicking:@[ tiffResult ]];
813-
814-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
815-
if (!resultExpectation.inverted) {
816-
XCTAssertFalse(emptyResultReceived, @"Observer should not fire when processing selection");
817-
}
818-
});
819-
812+
813+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)),
814+
dispatch_get_main_queue(), ^{
815+
if (!resultExpectation.inverted) {
816+
XCTAssertFalse(emptyResultReceived,
817+
@"Observer should not fire when processing selection");
818+
}
819+
});
820+
820821
[self waitForExpectationsWithTimeout:5.0 handler:nil];
821822
}
822823

823824
- (void)testObserverRespectsContextClearing {
824825
id photoLibrary = OCMClassMock([PHPhotoLibrary class]);
825826
OCMStub(ClassMethod([photoLibrary authorizationStatus]))
826827
.andReturn(PHAuthorizationStatusAuthorized);
827-
828+
828829
FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init];
829830
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
830831
[plugin setImagePickerControllerOverrides:@[ controller ]];
831-
832+
832833
XCTestExpectation *resultExpectation = [self expectationWithDescription:@"result"];
833834
__block NSInteger completionCallCount = 0;
834-
835+
835836
[plugin pickImageWithSource:[FLTSourceSpecification makeWithType:FLTSourceTypeGallery
836837
camera:FLTSourceCameraRear]
837838
maxSize:[[FLTMaxSize alloc] init]
@@ -841,41 +842,42 @@ - (void)testObserverRespectsContextClearing {
841842
completionCallCount++;
842843
[resultExpectation fulfill];
843844
}];
844-
845+
845846
XCTAssertNotNil(plugin.callContext, @"Context should be set after pickImage call");
846-
847+
847848
plugin.callContext = nil;
848-
849+
849850
UIView *controllerView = controller.view;
850851
if (controllerView) {
851852
UIWindow *testWindow = [[UIWindow alloc] init];
852853
[testWindow addSubview:controllerView];
853854
[controllerView removeFromSuperview];
854855
}
855-
856-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
857-
XCTAssertLessThanOrEqual(completionCallCount, 1,
858-
@"Observer should not fire after context is cleared");
859-
if (completionCallCount == 0) {
860-
[resultExpectation fulfill];
861-
}
862-
});
863-
856+
857+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)),
858+
dispatch_get_main_queue(), ^{
859+
XCTAssertLessThanOrEqual(completionCallCount, 1,
860+
@"Observer should not fire after context is cleared");
861+
if (completionCallCount == 0) {
862+
[resultExpectation fulfill];
863+
}
864+
});
865+
864866
[self waitForExpectationsWithTimeout:1.0 handler:nil];
865867
}
866868

867869
- (void)testObserverDelayAllowsDelegateMethodsToRunFirst {
868870
id photoLibrary = OCMClassMock([PHPhotoLibrary class]);
869871
OCMStub(ClassMethod([photoLibrary authorizationStatus]))
870872
.andReturn(PHAuthorizationStatusAuthorized);
871-
873+
872874
FLTImagePickerPlugin *plugin = [[FLTImagePickerPlugin alloc] init];
873875
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
874876
[plugin setImagePickerControllerOverrides:@[ controller ]];
875-
877+
876878
XCTestExpectation *resultExpectation = [self expectationWithDescription:@"result"];
877879
__block NSInteger callCount = 0;
878-
880+
879881
[plugin pickImageWithSource:[FLTSourceSpecification makeWithType:FLTSourceTypeGallery
880882
camera:FLTSourceCameraRear]
881883
maxSize:[[FLTMaxSize alloc] init]
@@ -886,23 +888,27 @@ - (void)testObserverDelayAllowsDelegateMethodsToRunFirst {
886888
if (callCount == 1) {
887889
XCTAssertNil(result);
888890
XCTAssertNil(error);
889-
891+
890892
UIView *controllerView = controller.view;
891893
if (controllerView) {
892894
UIWindow *testWindow = [[UIWindow alloc] init];
893895
[testWindow addSubview:controllerView];
894896
[controllerView removeFromSuperview];
895897
}
896-
897-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
898-
XCTAssertEqual(callCount, 1, @"Observer should not fire after context cleared by cancel");
899-
[resultExpectation fulfill];
900-
});
898+
899+
dispatch_after(
900+
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)),
901+
dispatch_get_main_queue(), ^{
902+
XCTAssertEqual(
903+
callCount, 1,
904+
@"Observer should not fire after context cleared by cancel");
905+
[resultExpectation fulfill];
906+
});
901907
}
902908
}];
903-
909+
904910
[plugin imagePickerControllerDidCancel:controller];
905-
911+
906912
[self waitForExpectationsWithTimeout:1.0 handler:nil];
907913
}
908914

packages/image_picker/image_picker_ios/ios/image_picker_ios/Sources/image_picker_ios/FLTImagePickerPlugin.m

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,22 @@ - (instancetype)initWithResult:(nonnull FlutterResultAdapter)result {
3333
typedef void (^FLTImagePickerRemoveCallback)(void);
3434

3535
/**
36-
* Add the view to the PickerViewController's view, observing its window to observe the window of PickerViewController.
37-
* This is to prevent PickerViewController from being removed from the screen without receiving callback information under other circumstances,
38-
* such as being interactively dismissed before PickerViewController has fully popped up.
36+
* Add the view to the PickerViewController's view, observing its window to observe the window of
37+
* PickerViewController. This is to prevent PickerViewController from being removed from the screen
38+
* without receiving callback information under other circumstances, such as being interactively
39+
* dismissed before PickerViewController has fully popped up.
3940
*/
4041
@interface FLTImagePickerRemoveObserverView : UIView
4142

4243
@property(nonatomic, copy, nonnull) FLTImagePickerRemoveCallback removeCallback;
4344

44-
-(instancetype)initWithRemoveCallback:(FLTImagePickerRemoveCallback)callback;
45+
- (instancetype)initWithRemoveCallback:(FLTImagePickerRemoveCallback)callback;
4546

4647
@end
4748

4849
@implementation FLTImagePickerRemoveObserverView
4950

50-
- (instancetype)initWithRemoveCallback:(FLTImagePickerRemoveCallback)callback{
51+
- (instancetype)initWithRemoveCallback:(FLTImagePickerRemoveCallback)callback {
5152
if (self = [super init]) {
5253
self.removeCallback = callback;
5354
}
@@ -56,7 +57,7 @@ - (instancetype)initWithRemoveCallback:(FLTImagePickerRemoveCallback)callback{
5657
- (void)didMoveToWindow {
5758
if (!self.window) {
5859
[self removeFromSuperview];
59-
[[NSOperationQueue mainQueue]addOperationWithBlock:self.removeCallback];
60+
[[NSOperationQueue mainQueue] addOperationWithBlock:self.removeCallback];
6061
}
6162
}
6263
@end
@@ -197,16 +198,17 @@ - (void)bindRemoveObserver:(nonnull UIViewController *)controller
197198
context:(nonnull FLTImagePickerMethodCallContext *)context {
198199
__weak typeof(self) weakSelf = self;
199200
FLTImagePickerRemoveObserverView *removeObserverView =
200-
[[FLTImagePickerRemoveObserverView alloc]initWithRemoveCallback:^{
201+
[[FLTImagePickerRemoveObserverView alloc] initWithRemoveCallback:^{
201202
__strong typeof(weakSelf) strongSelf = weakSelf;
202-
// Add a small delay to ensure delegate methods have a chance to run first
203-
// This prevents the observer from firing during normal selection flow
204-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
205-
if(strongSelf && strongSelf.callContext == context && !strongSelf.isProcessingSelection) {
206-
// Only send result if context is still active and we're not processing a selection
207-
[strongSelf sendCallResultWithSavedPathList:nil];
208-
}
209-
});
203+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)),
204+
dispatch_get_main_queue(), ^{
205+
if (strongSelf && strongSelf.callContext == context &&
206+
!strongSelf.isProcessingSelection) {
207+
// Only send result if context is still active and we're not processing a
208+
// selection
209+
[strongSelf sendCallResultWithSavedPathList:nil];
210+
}
211+
});
210212
}];
211213
[controller.view addSubview:removeObserverView];
212214
}

0 commit comments

Comments
 (0)