Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 41d899d

Browse files
committed
[camera]add prefix for flashmode enum, and use modulemap
1 parent 5bae312 commit 41d899d

File tree

9 files changed

+87
-86
lines changed

9 files changed

+87
-86
lines changed

packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
2323
E01EE4A82799F3A5008C1950 /* QueueHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E01EE4A72799F3A5008C1950 /* QueueHelperTests.m */; };
2424
E032F250279F5E94009E9028 /* CameraCaptureSessionQueueRaceConditionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E032F24F279F5E94009E9028 /* CameraCaptureSessionQueueRaceConditionTests.m */; };
25-
E032F2A727A0BF2D009E9028 /* FlashModeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E032F2A627A0BF2D009E9028 /* FlashModeTests.m */; };
25+
E032F2A727A0BF2D009E9028 /* FLTFlashModeTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E032F2A627A0BF2D009E9028 /* FLTFlashModeTests.m */; };
2626
E0C6E2002770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C6E1FD2770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m */; };
2727
E0C6E2012770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C6E1FE2770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m */; };
2828
E0C6E2022770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C6E1FF2770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m */; };
@@ -82,7 +82,7 @@
8282
A24F9E418BA48BCC7409B117 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = "<group>"; };
8383
E01EE4A72799F3A5008C1950 /* QueueHelperTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QueueHelperTests.m; sourceTree = "<group>"; };
8484
E032F24F279F5E94009E9028 /* CameraCaptureSessionQueueRaceConditionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CameraCaptureSessionQueueRaceConditionTests.m; sourceTree = "<group>"; };
85-
E032F2A627A0BF2D009E9028 /* FlashModeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FlashModeTests.m; sourceTree = "<group>"; };
85+
E032F2A627A0BF2D009E9028 /* FLTFlashModeTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLTFlashModeTests.m; sourceTree = "<group>"; };
8686
E0C6E1FD2770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadSafeMethodChannelTests.m; sourceTree = "<group>"; };
8787
E0C6E1FE2770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadSafeTextureRegistryTests.m; sourceTree = "<group>"; };
8888
E0C6E1FF2770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadSafeEventChannelTests.m; sourceTree = "<group>"; };
@@ -127,7 +127,7 @@
127127
F6EE622E2710A6FC00905E4A /* MockFLTThreadSafeFlutterResult.m */,
128128
F63F9EED27143B19002479BF /* MockFLTThreadSafeFlutterResult.h */,
129129
E032F24F279F5E94009E9028 /* CameraCaptureSessionQueueRaceConditionTests.m */,
130-
E032F2A627A0BF2D009E9028 /* FlashModeTests.m */,
130+
E032F2A627A0BF2D009E9028 /* FLTFlashModeTests.m */,
131131
);
132132
path = RunnerTests;
133133
sourceTree = "<group>";
@@ -391,7 +391,7 @@
391391
buildActionMask = 2147483647;
392392
files = (
393393
03F6F8B226CBB4670024B8D3 /* ThreadSafeFlutterResultTests.m in Sources */,
394-
E032F2A727A0BF2D009E9028 /* FlashModeTests.m in Sources */,
394+
E032F2A727A0BF2D009E9028 /* FLTFlashModeTests.m in Sources */,
395395
033B94BE269C40A200B4DF97 /* CameraMethodChannelTests.m in Sources */,
396396
03BB766B2665316900CE5A93 /* CameraFocusTests.m in Sources */,
397397
E487C86026D686A10034AC92 /* CameraPreviewPauseTests.m in Sources */,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
@import camera.Test;
6+
@import AVFoundation;
7+
#import <XCTest/XCTest.h>
8+
9+
@interface FLTFlashModeTests : XCTestCase
10+
11+
@end
12+
13+
@implementation FLTFlashModeTests
14+
15+
- (void)testGetFLTFlashModeForString {
16+
XCTAssertEqual(FLTFlashModeOff, getFLTFlashModeForString(@"off"));
17+
XCTAssertEqual(FLTFlashModeAuto, getFLTFlashModeForString(@"auto"));
18+
XCTAssertEqual(FLTFlashModeAlways, getFLTFlashModeForString(@"always"));
19+
XCTAssertEqual(FLTFlashModeTorch, getFLTFlashModeForString(@"torch"));
20+
XCTAssertThrows(getFLTFlashModeForString(@"unkwown"));
21+
}
22+
23+
- (void)testGetAVCaptureFlashModeForFLTFlashMode {
24+
XCTAssertEqual(AVCaptureFlashModeOff, getAVCaptureFlashModeForFLTFlashMode(FLTFlashModeOff));
25+
XCTAssertEqual(AVCaptureFlashModeAuto, getAVCaptureFlashModeForFLTFlashMode(FLTFlashModeAuto));
26+
XCTAssertEqual(AVCaptureFlashModeOn, getAVCaptureFlashModeForFLTFlashMode(FLTFlashModeAlways));
27+
XCTAssertEqual(-1, getAVCaptureFlashModeForFLTFlashMode(FLTFlashModeTorch));
28+
}
29+
30+
@end

packages/camera/camera/example/ios/RunnerTests/FlashModeTests.m

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/camera/camera/ios/Classes/CameraPlugin.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
#import <CoreMotion/CoreMotion.h>
1111
#import <libkern/OSAtomic.h>
1212
#import <uuid/uuid.h>
13+
#import "FLTFlashMode.h"
1314
#import "FLTThreadSafeEventChannel.h"
1415
#import "FLTThreadSafeFlutterResult.h"
1516
#import "FLTThreadSafeMethodChannel.h"
1617
#import "FLTThreadSafeTextureRegistry.h"
17-
#import "FlashMode.h"
1818

1919
@interface FLTSavePhotoDelegate : NSObject <AVCapturePhotoCaptureDelegate>
2020
@property(readonly, nonatomic) NSString *path;
@@ -308,7 +308,7 @@ @interface FLTCam : NSObject <FlutterTexture,
308308
@property(assign, nonatomic) ResolutionPreset resolutionPreset;
309309
@property(assign, nonatomic) ExposureMode exposureMode;
310310
@property(assign, nonatomic) FocusMode focusMode;
311-
@property(assign, nonatomic) FlashMode flashMode;
311+
@property(assign, nonatomic) FLTFlashMode flashMode;
312312
@property(assign, nonatomic) UIDeviceOrientation lockedCaptureOrientation;
313313
@property(assign, nonatomic) CMTime lastVideoSampleTime;
314314
@property(assign, nonatomic) CMTime lastAudioSampleTime;
@@ -345,7 +345,7 @@ - (instancetype)initWithCameraName:(NSString *)cameraName
345345
_captureSessionQueue = captureSessionQueue;
346346
_captureSession = [[AVCaptureSession alloc] init];
347347
_captureDevice = [AVCaptureDevice deviceWithUniqueID:cameraName];
348-
_flashMode = _captureDevice.hasFlash ? FlashModeAuto : FlashModeOff;
348+
_flashMode = _captureDevice.hasFlash ? FLTFlashModeAuto : FLTFlashModeOff;
349349
_exposureMode = ExposureModeAuto;
350350
_focusMode = FocusModeAuto;
351351
_lockedCaptureOrientation = UIDeviceOrientationUnknown;
@@ -447,7 +447,7 @@ - (void)captureToFile:(FLTThreadSafeFlutterResult *)result API_AVAILABLE(ios(10)
447447
[settings setHighResolutionPhotoEnabled:YES];
448448
}
449449

450-
AVCaptureFlashMode avFlashMode = getAVCaptureFlashModeForFlashMode(_flashMode);
450+
AVCaptureFlashMode avFlashMode = getAVCaptureFlashModeForFLTFlashMode(_flashMode);
451451
if (avFlashMode != -1) {
452452
[settings setFlashMode:avFlashMode];
453453
}
@@ -892,14 +892,14 @@ - (void)unlockCaptureOrientationWithResult:(FLTThreadSafeFlutterResult *)result
892892
}
893893

894894
- (void)setFlashModeWithResult:(FLTThreadSafeFlutterResult *)result mode:(NSString *)modeStr {
895-
FlashMode mode;
895+
FLTFlashMode mode;
896896
@try {
897-
mode = getFlashModeForString(modeStr);
897+
mode = getFLTFlashModeForString(modeStr);
898898
} @catch (NSError *e) {
899899
[result sendError:e];
900900
return;
901901
}
902-
if (mode == FlashModeTorch) {
902+
if (mode == FLTFlashModeTorch) {
903903
if (!_captureDevice.hasTorch) {
904904
[result sendErrorWithCode:@"setFlashModeFailed"
905905
message:@"Device does not support torch mode"
@@ -924,7 +924,7 @@ - (void)setFlashModeWithResult:(FLTThreadSafeFlutterResult *)result mode:(NSStri
924924
details:nil];
925925
return;
926926
}
927-
AVCaptureFlashMode avFlashMode = getAVCaptureFlashModeForFlashMode(mode);
927+
AVCaptureFlashMode avFlashMode = getAVCaptureFlashModeForFLTFlashMode(mode);
928928
if (![_capturePhotoOutput.supportedFlashModes
929929
containsObject:[NSNumber numberWithInt:((int)avFlashMode)]]) {
930930
[result sendErrorWithCode:@"setFlashModeFailed"
@@ -1240,7 +1240,7 @@ - (BOOL)setupWriterForPath:(NSString *)path {
12401240
[_audioOutput setSampleBufferDelegate:self queue:_captureSessionQueue];
12411241
}
12421242

1243-
if (_flashMode == FlashModeTorch) {
1243+
if (_flashMode == FLTFlashModeTorch) {
12441244
[self.captureDevice lockForConfiguration:nil];
12451245
[self.captureDevice setTorchMode:AVCaptureTorchModeOn];
12461246
[self.captureDevice unlockForConfiguration];

packages/camera/camera/ios/Classes/CameraPlugin.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ framework module camera {
66

77
explicit module Test {
88
header "CameraPlugin_Test.h"
9+
header "FLTFlashMode.h"
910
}
1011
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import <AVFoundation/AVFoundation.h>
6+
#import <Foundation/Foundation.h>
7+
8+
NS_ASSUME_NONNULL_BEGIN
9+
10+
/**
11+
* Represents camera's flash mode. Mirrors `FlashMode` enum in flash_mode.dart.
12+
*/
13+
typedef NS_ENUM(NSInteger, FLTFlashMode) {
14+
FLTFlashModeOff,
15+
FLTFlashModeAuto,
16+
FLTFlashModeAlways,
17+
FLTFlashModeTorch,
18+
};
19+
20+
/**
21+
* Gets FLTFlashMode from its string representation.
22+
* @param mode a string representation of the FLTFlashMode.
23+
*/
24+
extern FLTFlashMode getFLTFlashModeForString(NSString *mode);
25+
26+
/**
27+
* Gets AVCaptureFlashMode from FLTFlashMode.
28+
* @param mode flash mode.
29+
*/
30+
extern AVCaptureFlashMode getAVCaptureFlashModeForFLTFlashMode(FLTFlashMode mode);
31+
32+
NS_ASSUME_NONNULL_END

packages/camera/camera/ios/Classes/FlashMode.m renamed to packages/camera/camera/ios/Classes/FLTFlashMode.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#import "FlashMode.h"
5+
#import "FLTFlashMode.h"
66

7-
FlashMode getFlashModeForString(NSString *mode) {
7+
FLTFlashMode getFLTFlashModeForString(NSString *mode) {
88
if ([mode isEqualToString:@"off"]) {
9-
return FlashModeOff;
9+
return FLTFlashModeOff;
1010
} else if ([mode isEqualToString:@"auto"]) {
11-
return FlashModeAuto;
11+
return FLTFlashModeAuto;
1212
} else if ([mode isEqualToString:@"always"]) {
13-
return FlashModeAlways;
13+
return FLTFlashModeAlways;
1414
} else if ([mode isEqualToString:@"torch"]) {
15-
return FlashModeTorch;
15+
return FLTFlashModeTorch;
1616
} else {
1717
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain
1818
code:NSURLErrorUnknown
@@ -24,15 +24,15 @@ FlashMode getFlashModeForString(NSString *mode) {
2424
}
2525
}
2626

27-
AVCaptureFlashMode getAVCaptureFlashModeForFlashMode(FlashMode mode) {
27+
AVCaptureFlashMode getAVCaptureFlashModeForFLTFlashMode(FLTFlashMode mode) {
2828
switch (mode) {
29-
case FlashModeOff:
29+
case FLTFlashModeOff:
3030
return AVCaptureFlashModeOff;
31-
case FlashModeAuto:
31+
case FLTFlashModeAuto:
3232
return AVCaptureFlashModeAuto;
33-
case FlashModeAlways:
33+
case FLTFlashModeAlways:
3434
return AVCaptureFlashModeOn;
35-
case FlashModeTorch:
35+
case FLTFlashModeTorch:
3636
default:
3737
return -1;
3838
}

packages/camera/camera/ios/Classes/FlashMode.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

packages/camera/camera/ios/Classes/camera-umbrella.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#import <camera/FLTThreadSafeFlutterResult.h>
99
#import <camera/FLTThreadSafeMethodChannel.h>
1010
#import <camera/FLTThreadSafeTextureRegistry.h>
11-
#import <camera/FlashMode.h>
1211
#import <camera/QueueHelper.h>
1312

1413
FOUNDATION_EXPORT double cameraVersionNumber;

0 commit comments

Comments
 (0)