Skip to content

Commit

Permalink
fix camera issue
Browse files Browse the repository at this point in the history
  • Loading branch information
shreya-mishra committed Sep 8, 2023
1 parent efdba8a commit fb173ac
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 36 deletions.
51 changes: 31 additions & 20 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rdsapp">
package="com.rdsapp">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true"
android:name=".MainApplication"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:scheme="https"
android:host="deeplink-check.netlify.app" />
<data android:host="deeplink-check.netlify.app" />
</intent-filter>
</activity>
</application>
</manifest>
56 changes: 40 additions & 16 deletions src/screens/AuthScreen/AuthScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { AuthViewStyle } from './styles';
import { AuthScreenButton } from './Button';
import { Toast } from 'react-native-toast-message/lib/src/Toast';
import { AuthContext } from '../../context/AuthContext';
import { getUserData } from './Util';
import { getUserData, requestCameraPermission } from './Util';
import { storeData } from '../../utils/dataStore';
import { SafeAreaView } from 'react-native-safe-area-context';
import { ActivityIndicator } from 'react-native';
Expand All @@ -33,13 +33,15 @@ const AuthScreen = () => {
const [cameraActive, setCameraActive] = useState(false);
const [scannedUserId, setScannedUserID] = useState('');
const [modalVisible, setModalVisible] = useState(false);
const [addressbarURL, setAdressbarURL] = useState<String>('');
const [key, setKey] = useState(1);

const activateCamera = async () => {
try {
// await Camera.requestCameraPermission(); // Request camera permission
setCameraActive(true); // Set cameraActive state to true
} catch (error) {
console.error('Error requesting camera permission:', error);
await requestCameraPermission();
setCameraActive((prev) => !prev); // Set cameraActive state to true
} catch (error: any) {
Alert.alert('Error requesting camera permission:', error);
}
};

Expand Down Expand Up @@ -197,17 +199,39 @@ const AuthScreen = () => {
<WebView
key={key}
onNavigationStateChange={({ url }) => {
if (url === urls.REDIRECT_URL) {
setAdressbarURL(url);
updateUserData(url);
} else if (url.indexOf('?') > 0) {
let uri = url.substring(0, url.indexOf('?'));
setAdressbarURL(uri);
updateUserData(uri);
} else {
setAdressbarURL(url);
updateUserData(url);
}
(async function () {
if (url === urls.REDIRECT_URL) {
setAdressbarURL(url);
try {
const res = await getUserData(url);
await storeData('userData', JSON.stringify(res));

setLoggedInUserData({
id: res?.id,
name: res?.name,
profileUrl: res?.profileUrl,
status: res?.status,
});
} catch (err) {
setLoggedInUserData(null);
}
} else if (url.indexOf('?') > 0) {
let uri = url.substring(0, url.indexOf('?'));
console.log(1, uri);
setAdressbarURL(uri);
setAdressbarURL(uri);
updateUserData(uri);
setAdressbarURL(uri);
updateUserData(uri);
} else {
console.log(2, url);
setAdressbarURL(url);
setAdressbarURL(url);
updateUserData(url);
setAdressbarURL(url);
updateUserData(url);
}
})();
}}
style={AuthViewStyle.webViewStyles}
source={{
Expand Down
24 changes: 24 additions & 0 deletions src/screens/AuthScreen/Util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';
import { urls } from '../../constants/appConstant/url';
import { PermissionsAndroid } from 'react-native';

export const getUserData = async (url: string) => {
if (url === urls.REDIRECT_URL) {
Expand Down Expand Up @@ -61,3 +62,26 @@ export const updateMarkYourSelfAs_ = async (markStatus: string) => {

export const isValidTextInput = (code: string) =>
Boolean(/^[\d]{1,4}$|^$/.test(code));

export const requestCameraPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,
{
title: 'Accessing your camera to scan the QR code',
message:
'RDS App needs access to your camera ' + 'so you can scan QR code',
buttonNeutral: 'Ask Me Later',
buttonNegative: 'Cancel',
buttonPositive: 'OK',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('You can use the camera');
} else {
console.log('Camera permission denied');
}
} catch (err) {
console.warn(err);
}
};

0 comments on commit fb173ac

Please sign in to comment.