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

Commit bcec41c

Browse files
committed
[camera]move flashmode out to a separate file
1 parent d20d3bf commit bcec41c

File tree

3 files changed

+68
-42
lines changed

3 files changed

+68
-42
lines changed

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

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import <CoreMotion/CoreMotion.h>
1111
#import <libkern/OSAtomic.h>
1212
#import <uuid/uuid.h>
13+
#import "FlashMode.h"
1314
#import "FLTThreadSafeEventChannel.h"
1415
#import "FLTThreadSafeFlutterResult.h"
1516
#import "FLTThreadSafeMethodChannel.h"
@@ -113,34 +114,6 @@ - (void)captureOutput:(AVCapturePhotoOutput *)output
113114
}
114115
@end
115116

116-
// Mirrors FlashMode in flash_mode.dart
117-
typedef enum {
118-
FlashModeOff,
119-
FlashModeAuto,
120-
FlashModeAlways,
121-
FlashModeTorch,
122-
} FlashMode;
123-
124-
static FlashMode getFlashModeForString(NSString *mode) {
125-
if ([mode isEqualToString:@"off"]) {
126-
return FlashModeOff;
127-
} else if ([mode isEqualToString:@"auto"]) {
128-
return FlashModeAuto;
129-
} else if ([mode isEqualToString:@"always"]) {
130-
return FlashModeAlways;
131-
} else if ([mode isEqualToString:@"torch"]) {
132-
return FlashModeTorch;
133-
} else {
134-
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain
135-
code:NSURLErrorUnknown
136-
userInfo:@{
137-
NSLocalizedDescriptionKey : [NSString
138-
stringWithFormat:@"Unknown flash mode %@", mode]
139-
}];
140-
@throw error;
141-
}
142-
}
143-
144117
static OSType getVideoFormatFromString(NSString *videoFormatString) {
145118
if ([videoFormatString isEqualToString:@"bgra8888"]) {
146119
return kCVPixelFormatType_32BGRA;
@@ -152,20 +125,6 @@ static OSType getVideoFormatFromString(NSString *videoFormatString) {
152125
}
153126
}
154127

155-
static AVCaptureFlashMode getAVCaptureFlashModeForFlashMode(FlashMode mode) {
156-
switch (mode) {
157-
case FlashModeOff:
158-
return AVCaptureFlashModeOff;
159-
case FlashModeAuto:
160-
return AVCaptureFlashModeAuto;
161-
case FlashModeAlways:
162-
return AVCaptureFlashModeOn;
163-
case FlashModeTorch:
164-
default:
165-
return -1;
166-
}
167-
}
168-
169128
// Mirrors ExposureMode in camera.dart
170129
typedef enum {
171130
ExposureModeAuto,
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// FlashMode.h
3+
// camera
4+
//
5+
// Created by Huan Lin on 1/25/22.
6+
//
7+
8+
#import <AVFoundation/AVFoundation.h>
9+
#import <Foundation/Foundation.h>
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
// Mirrors FlashMode in flash_mode.dart
14+
typedef enum {
15+
FlashModeOff,
16+
FlashModeAuto,
17+
FlashModeAlways,
18+
FlashModeTorch,
19+
} FlashMode;
20+
21+
FlashMode getFlashModeForString(NSString *mode);
22+
AVCaptureFlashMode getAVCaptureFlashModeForFlashMode(FlashMode mode);
23+
24+
NS_ASSUME_NONNULL_END
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// FlashMode.m
3+
// camera
4+
//
5+
// Created by Huan Lin on 1/25/22.
6+
//
7+
8+
#import "FlashMode.h"
9+
10+
FlashMode getFlashModeForString(NSString *mode) {
11+
if ([mode isEqualToString:@"off"]) {
12+
return FlashModeOff;
13+
} else if ([mode isEqualToString:@"auto"]) {
14+
return FlashModeAuto;
15+
} else if ([mode isEqualToString:@"always"]) {
16+
return FlashModeAlways;
17+
} else if ([mode isEqualToString:@"torch"]) {
18+
return FlashModeTorch;
19+
} else {
20+
NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain
21+
code:NSURLErrorUnknown
22+
userInfo:@{
23+
NSLocalizedDescriptionKey : [NSString
24+
stringWithFormat:@"Unknown flash mode %@", mode]
25+
}];
26+
@throw error;
27+
}
28+
}
29+
30+
AVCaptureFlashMode getAVCaptureFlashModeForFlashMode(FlashMode mode) {
31+
switch (mode) {
32+
case FlashModeOff:
33+
return AVCaptureFlashModeOff;
34+
case FlashModeAuto:
35+
return AVCaptureFlashModeAuto;
36+
case FlashModeAlways:
37+
return AVCaptureFlashModeOn;
38+
case FlashModeTorch:
39+
default:
40+
return -1;
41+
}
42+
}
43+

0 commit comments

Comments
 (0)