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

Commit 134173f

Browse files
committed
feat(ios): enhanced advanced example project
- added the custom white balance feature (#2774) to the advanced example project
1 parent c434051 commit 134173f

File tree

4 files changed

+127
-22
lines changed

4 files changed

+127
-22
lines changed

examples/advanced/advanced/ios/Podfile.lock

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,15 @@ PODS:
182182
- React-cxxreact (= 0.61.4)
183183
- React-jsi (= 0.61.4)
184184
- React-jsinspector (0.61.4)
185-
- react-native-camera (3.9.0):
185+
- react-native-camera (3.28.0):
186186
- React
187-
- react-native-camera/RCT (= 3.9.0)
188-
- react-native-camera/RN (= 3.9.0)
189-
- react-native-camera/RCT (3.9.0):
187+
- react-native-camera/RCT (= 3.28.0)
188+
- react-native-camera/RN (= 3.28.0)
189+
- react-native-camera/RCT (3.28.0):
190190
- React
191-
- react-native-camera/RN (3.9.0):
191+
- react-native-camera/RN (3.28.0):
192+
- React
193+
- react-native-slider (3.0.0):
192194
- React
193195
- React-RCTActionSheet (0.61.4):
194196
- React-Core/RCTActionSheetHeaders (= 0.61.4)
@@ -247,6 +249,7 @@ DEPENDENCIES:
247249
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
248250
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
249251
- react-native-camera (from `../node_modules/react-native-camera`)
252+
- "react-native-slider (from `../node_modules/@react-native-community/slider`)"
250253
- React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`)
251254
- React-RCTAnimation (from `../node_modules/react-native/Libraries/NativeAnimation`)
252255
- React-RCTBlob (from `../node_modules/react-native/Libraries/Blob`)
@@ -262,7 +265,7 @@ DEPENDENCIES:
262265
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
263266

264267
SPEC REPOS:
265-
https://github.com/cocoapods/specs.git:
268+
trunk:
266269
- boost-for-react-native
267270

268271
EXTERNAL SOURCES:
@@ -296,6 +299,8 @@ EXTERNAL SOURCES:
296299
:path: "../node_modules/react-native/ReactCommon/jsinspector"
297300
react-native-camera:
298301
:path: "../node_modules/react-native-camera"
302+
react-native-slider:
303+
:path: "../node_modules/@react-native-community/slider"
299304
React-RCTActionSheet:
300305
:path: "../node_modules/react-native/Libraries/ActionSheetIOS"
301306
React-RCTAnimation:
@@ -337,7 +342,8 @@ SPEC CHECKSUMS:
337342
React-jsi: ca921f4041505f9d5197139b2d09eeb020bb12e8
338343
React-jsiexecutor: 8dfb73b987afa9324e4009bdce62a18ce23d983c
339344
React-jsinspector: d15478d0a8ada19864aa4d1cc1c697b41b3fa92f
340-
react-native-camera: 8ad12cae113fd60b07236983532acc8e595c0fc3
345+
react-native-camera: 17d755c4334e77dad0ec6337faaded5274f18464
346+
react-native-slider: 05f11678260cb27c3d00a2dd1558b623be3ec8d2
341347
React-RCTActionSheet: 7369b7c85f99b6299491333affd9f01f5a130c22
342348
React-RCTAnimation: d07be15b2bd1d06d89417eb0343f98ffd2b099a7
343349
React-RCTBlob: 8e0b23d95c9baa98f6b0e127e07666aaafd96c34
@@ -353,4 +359,4 @@ SPEC CHECKSUMS:
353359

354360
PODFILE CHECKSUM: 27b3847fe4d98bb58146c377f86ebed45b40a77d
355361

356-
COCOAPODS: 1.7.5
362+
COCOAPODS: 1.9.1

examples/advanced/advanced/package-lock.json

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/advanced/advanced/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
"lint": "eslint ."
1111
},
1212
"dependencies": {
13+
"@react-native-community/slider": "^3.0.0",
14+
"native-base": "2.13.8",
1315
"react": "16.11.0",
1416
"react-native": "0.61.4",
17+
"react-native-camera": "^3.28.0",
18+
"react-native-gesture-handler": "1.5.0",
1519
"react-navigation": "4.0.10",
1620
"react-navigation-stack": "1.10.3",
17-
"native-base": "2.13.8",
18-
"react-native-gesture-handler": "1.5.0",
19-
"underscore": "1.9.1",
20-
"react-native-camera": "*"
21+
"underscore": "1.9.1"
2122
},
2223
"devDependencies": {
2324
"@babel/core": "7.7.2",

examples/advanced/advanced/src/screens/Camera.js

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
AppState,
1010
TouchableOpacity
1111
} from 'react-native';
12+
import Slider from '@react-native-community/slider';
1213
import _ from 'underscore';
1314
import { Container, Button, Text, Icon, Footer, FooterTab, Spinner, H2, connectStyle, Toast } from 'native-base';
1415
import { RNCamera } from 'react-native-camera';
@@ -50,9 +51,18 @@ const WB_OPTIONS_MAP = {
5051
2: "CL",
5152
3: "SH",
5253
4: "IN",
53-
5: "FL"
54+
5: "FL",
55+
6: "CW"
5456
}
5557

58+
const CUSTOM_WB_OPTIONS_MAP = {
59+
temperature: {label: "Temp.", min: 1000, max: 10000, steps: 500},
60+
tint: {label: "Tint", min: -20, max: 20, steps: 0.5},
61+
redGainOffset: {label: "Red", min: -1.0, max: 1.0, steps: 0.05},
62+
greenGainOffset: {label: "Green", min: -1.0, max: 1.0, steps: 0.05},
63+
blueGainOffset: {label: "Blue", min: -1.0, max: 1.0, steps: 0.05},
64+
};
65+
5666
const getCameraType = (type) => {
5767

5868
if(type == 'AVCaptureDeviceTypeBuiltInTelephotoCamera'){
@@ -95,6 +105,7 @@ const styles = StyleSheet.create({
95105

96106
buttonsView: {
97107
flex: 1,
108+
backgroundColor: 'black',
98109
width: '100%',
99110
flexDirection: 'row',
100111
alignItems: 'center',
@@ -111,6 +122,31 @@ const styles = StyleSheet.create({
111122
ratioButton: {
112123
width: 100 * conf.theme.variables.sizeScaling
113124
},
125+
126+
customWBView: {
127+
backgroundColor: '#00000080',
128+
flex: 1,
129+
width: '100%',
130+
height: 50,
131+
flexDirection: 'row',
132+
alignItems: 'center',
133+
paddingHorizontal: 8,
134+
},
135+
136+
customWBViewButton: {
137+
backgroundColor: 'transparent',
138+
alignSelf: 'center',
139+
width: '25%',
140+
},
141+
142+
customWBViewText: {
143+
color: 'white',
144+
},
145+
146+
customWBViewSlider: {
147+
flex: 2,
148+
marginRight: 6,
149+
},
114150
})
115151

116152

@@ -120,8 +156,16 @@ const defaultCameraOptions = {
120156
flashMode: 'off', // on, auto, off, torch
121157
wb: 0,
122158
zoom: 0, // 0-1
123-
focusCoords: undefined
124-
}
159+
focusCoords: undefined,
160+
currentCustomWBOption: "temperature",
161+
customWhiteBalance: {
162+
temperature: 6000,
163+
tint: 0.0,
164+
redGainOffset: 0.0,
165+
greenGainOffset: 0.0,
166+
blueGainOffset: 0.0,
167+
},
168+
};
125169

126170
function parseRatio(str){
127171
let [p1, p2] = str.split(":");
@@ -601,6 +645,35 @@ class Camera extends Component{
601645

602646
this.cameraStyle = cameraStyle;
603647

648+
let whiteBalance;
649+
let customWBView;
650+
if (wb >= WB_OPTIONS.length) {
651+
let currentOption = this.state.currentCustomWBOption;
652+
let currentValue = this.state.customWhiteBalance[currentOption];
653+
let options = CUSTOM_WB_OPTIONS_MAP[currentOption]
654+
customWBView = (
655+
<View style={styles.customWBView}>
656+
<Button style={styles.customWBViewButton} onPress={this.changeCustomWBOption}>
657+
<Text style={styles.customWBViewText}>{options.label}</Text>
658+
</Button>
659+
<Slider
660+
style={styles.customWBViewSlider}
661+
value={currentValue}
662+
step={options.steps}
663+
minimumValue={options.min}
664+
maximumValue={options.max}
665+
minimumTrackTintColor="#FFFFFF"
666+
maximumTrackTintColor="#000000"
667+
onValueChange={this.changeCustomWBOptionValue}
668+
/>
669+
<Text style={[styles.customWBViewText, {minWidth: '15%'}]}>{currentValue.toFixed(1)}</Text>
670+
</View>
671+
);
672+
whiteBalance = this.state.customWhiteBalance;
673+
} else {
674+
whiteBalance = WB_OPTIONS[wb];
675+
}
676+
604677
return (
605678

606679
<Container fullBlack>
@@ -638,7 +711,7 @@ class Camera extends Component{
638711
maxZoom={MAX_ZOOM}
639712
useNativeZoom={true}
640713
onTap={this.onTapToFocus}
641-
whiteBalance={WB_OPTIONS[wb]}
714+
whiteBalance={whiteBalance}
642715
autoFocusPointOfInterest={this.state.focusCoords}
643716
androidCameraPermissionOptions={{
644717
title: 'Permission to use camera',
@@ -701,6 +774,7 @@ class Camera extends Component{
701774
/>
702775
</View>
703776
: null}
777+
{customWBView}
704778
<View style={styles.buttonsView}>
705779
<Button
706780
transparent
@@ -877,9 +951,28 @@ class Camera extends Component{
877951

878952

879953
changeWB = () => {
954+
// The custom white balance feature is only available on iOS (#2774)
955+
const numberOfOptions = IS_IOS ? Object.keys(WB_OPTIONS_MAP).length : WB_OPTIONS.length;
956+
this.setState({
957+
wb: (this.state.wb + 1) % numberOfOptions
958+
});
959+
}
960+
961+
changeCustomWBOption = () => {
962+
const optionKeys = Object.keys(CUSTOM_WB_OPTIONS_MAP);
963+
let currentOptionIndex = optionKeys.indexOf(this.state.currentCustomWBOption);
964+
let nextOptionIndex = (currentOptionIndex + 1) % optionKeys.length;
880965
this.setState({
881-
wb: (this.state.wb + 1) % WB_OPTIONS.length
882-
})
966+
currentCustomWBOption: optionKeys[nextOptionIndex]
967+
});
968+
}
969+
970+
changeCustomWBOptionValue = (value) => {
971+
let customWhiteBalance = {...this.state.customWhiteBalance};
972+
customWhiteBalance[this.state.currentCustomWBOption] = value;
973+
this.setState({
974+
customWhiteBalance: customWhiteBalance
975+
});
883976
}
884977

885978
toggleRatio = () => {
@@ -945,4 +1038,4 @@ Camera.navigationOptions = ({ navigation }) => {
9451038
Camera = connectStyle("Branding")(Camera);
9461039

9471040

948-
export default Camera;
1041+
export default Camera;

0 commit comments

Comments
 (0)