9
9
AppState ,
10
10
TouchableOpacity
11
11
} from 'react-native' ;
12
+ import Slider from '@react-native-community/slider' ;
12
13
import _ from 'underscore' ;
13
14
import { Container , Button , Text , Icon , Footer , FooterTab , Spinner , H2 , connectStyle , Toast } from 'native-base' ;
14
15
import { RNCamera } from 'react-native-camera' ;
@@ -50,9 +51,18 @@ const WB_OPTIONS_MAP = {
50
51
2 : "CL" ,
51
52
3 : "SH" ,
52
53
4 : "IN" ,
53
- 5 : "FL"
54
+ 5 : "FL" ,
55
+ 6 : "CW"
54
56
}
55
57
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
+
56
66
const getCameraType = ( type ) => {
57
67
58
68
if ( type == 'AVCaptureDeviceTypeBuiltInTelephotoCamera' ) {
@@ -95,6 +105,7 @@ const styles = StyleSheet.create({
95
105
96
106
buttonsView : {
97
107
flex : 1 ,
108
+ backgroundColor : 'black' ,
98
109
width : '100%' ,
99
110
flexDirection : 'row' ,
100
111
alignItems : 'center' ,
@@ -111,6 +122,31 @@ const styles = StyleSheet.create({
111
122
ratioButton : {
112
123
width : 100 * conf . theme . variables . sizeScaling
113
124
} ,
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
+ } ,
114
150
} )
115
151
116
152
@@ -120,8 +156,16 @@ const defaultCameraOptions = {
120
156
flashMode : 'off' , // on, auto, off, torch
121
157
wb : 0 ,
122
158
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
+ } ;
125
169
126
170
function parseRatio ( str ) {
127
171
let [ p1 , p2 ] = str . split ( ":" ) ;
@@ -601,6 +645,35 @@ class Camera extends Component{
601
645
602
646
this . cameraStyle = cameraStyle ;
603
647
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
+
604
677
return (
605
678
606
679
< Container fullBlack >
@@ -638,7 +711,7 @@ class Camera extends Component{
638
711
maxZoom = { MAX_ZOOM }
639
712
useNativeZoom = { true }
640
713
onTap = { this . onTapToFocus }
641
- whiteBalance = { WB_OPTIONS [ wb ] }
714
+ whiteBalance = { whiteBalance }
642
715
autoFocusPointOfInterest = { this . state . focusCoords }
643
716
androidCameraPermissionOptions = { {
644
717
title : 'Permission to use camera' ,
@@ -701,6 +774,7 @@ class Camera extends Component{
701
774
/>
702
775
</ View >
703
776
: null }
777
+ { customWBView }
704
778
< View style = { styles . buttonsView } >
705
779
< Button
706
780
transparent
@@ -877,9 +951,28 @@ class Camera extends Component{
877
951
878
952
879
953
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 ;
880
965
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
+ } ) ;
883
976
}
884
977
885
978
toggleRatio = ( ) => {
@@ -945,4 +1038,4 @@ Camera.navigationOptions = ({ navigation }) => {
945
1038
Camera = connectStyle ( "Branding" ) ( Camera ) ;
946
1039
947
1040
948
- export default Camera ;
1041
+ export default Camera ;
0 commit comments