Przeglądaj źródła

Add torchlight function
https://dev.wormwood.com.sg/zentao/task-view-231.html

vbea 2 lat temu
rodzic
commit
67085e1564

+ 27 - 3
Strides-APP/app/pages/charge/QRScan.js

@@ -3,7 +3,7 @@
  * @邠心vbe on 2021/03/24
  */
 import React, { Component } from 'react'
-import { StyleSheet, View } from 'react-native'
+import { Pressable, StyleSheet, View } from 'react-native'
 import QRCodeScanner from 'react-native-qrcode-scanner';
 import { RNCamera } from 'react-native-camera';
 import apiCharge from '../../api/apiCharge';
@@ -83,7 +83,8 @@ export default class QRScan extends Component {
     super(props);
     this.state={
       isResult: true,
-      params: this.props.route.params
+      params: this.props.route.params,
+      flashLight: false
     }
   }
 
@@ -182,6 +183,12 @@ export default class QRScan extends Component {
     })
   }
 
+  switchFlash() {
+    this.setState({
+      flashLight: !this.state.flashLight
+    })
+  }
+
   render() {
     return (
       <View style={styles.container}>
@@ -193,13 +200,23 @@ export default class QRScan extends Component {
               reactivateTimeout={1000}
               cameraStyle={{ width: $width, height: $vh(100)}}
               containerStyle={{ width: $width, height: $vh(100)}}
-              flashMode={RNCamera.Constants.FlashMode.off}
+              flashMode={this.state.flashLight ? RNCamera.Constants.FlashMode.torch : RNCamera.Constants.FlashMode.off}
               checkAndroid6Permissions={true} />
           : <View style={ui.flex1}></View>
           /*<Image
               style={Styles.logo}
               source={require('../../images/app-logo.png')}/> */
         }
+        { !this.state.isResult &&
+          <Pressable
+            style={styles.flashLight}
+            onPress={() => this.switchFlash()}>
+            <MaterialIcons
+              name={this.state.flashLight ? "flashlight-on" : "flashlight-off"}
+              size={36}
+              color="#fff"/>
+          </Pressable>
+        }
       </View>
     );
   }
@@ -211,6 +228,13 @@ const styles = StyleSheet.create({
     justifyContent: 'center',
     backgroundColor: '#000',
     ...StyleSheet.absoluteFillObject
+  },
+  flashLight: {
+    bottom: 90,
+    zIndex: 2,
+    opacity: 0.7,
+    padding: 8,
+    position: 'absolute'
   }
 })
 

+ 1 - 1
Strides-APP/app/pages/home/maps/LocationPermission.js

@@ -23,7 +23,7 @@ class LocationListener {
   }
   
   addListener() {
-    this.listener = LocationEnabler.addListener(({ locationEnabled }) => {
+    this.listener = LocationEnabler?.addListener(({ locationEnabled }) => {
       if (!locationEnabled) {
         console.log("status: " + this.status  + "," + locationEnabled);
         if (this.status != locationEnabled) {