Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bootstrapAsync = async () => {
// bootstrap the application
// async storage key 'userData' : {
// userToken: String,
// nameornym: String,
// avatarUri: String
// }
try {
// add user permssions
const cam = await Permissions.getAsync(Permissions.CAMERA);
const camr = await Permissions.getAsync(Permissions.CAMERA_ROLL);
// console.warn(cam);
// console.warn(camr);
// load font
await Font.loadAsync({
EurostileRegular: require('../assets/fonts/EurostileRegular.ttf'),
'ApexNew-Book': require('../assets/fonts/ApexNew-Book.otf'),
'ApexNew-Medium': require('../assets/fonts/ApexNew-Medium.otf'),
'ApexNew-Light': require('../assets/fonts/ApexNew-Light.otf'),
});
// load user data
let userData = await AsyncStorage.getItem('userData');
if (userData !== null) {
userData = JSON.parse(userData);
store.dispatch(setUpDefault(userData));
} else {
KeepAwake.deactivate();
() => (
KeepAwake.deactivate();
() => (
_verifyPermissions = async () => {
console.log("Verifying Permissions");
const { status, expires, permissions } = await Permissions.getAsync(Permissions.CAMERA, Permissions.CAMERA_ROLL);
if (status !== 'granted') {
const { status, permissions } = await Permissions.askAsync(Permissions.CAMERA, Permissions.CAMERA_ROLL)
if (status === 'granted') {
console.log("Permissions granted");
return true
} else {
alert('Hey! You have not enabled selected permissions');
return false
}
}else{
return true;
}
};
askPermissionsAsync = async () => {
const camera = await Permissions.askAsync(Permissions.CAMERA);
const cameraRoll = await Permissions.askAsync(Permissions.CAMERA_ROLL);
this.setState({
hasCameraPermission: camera.status === 'granted',
hasCameraRollPermission: cameraRoll.status === 'granted'
});
};
handleChooseProfilePictureChange = async () => {
const {status} = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === 'granted') {
const result = await ImagePicker.launchImageLibraryAsync({
mediaType: 'photo',
allowsEditing: true,
});
if (!result.cancelled) {
this.setState({
avatar: result.uri,
newAvatar: true,
});
} else {
this.setState({errorMessage: 'Location permission not granted'});
}
}
};
async componentDidMount() {
this.setState({isMounted: true});
const {status} = await Permissions.getAsync(Permissions.CAMERA_ROLL);
if (this.state.isMounted) {
this.setState({ hasCameraRollPermission: status === 'granted' });
if (status === 'granted') {
this.getPhotos();
} else {
const {status} = await Permissions.askAsync(Permissions.CAMERA_ROLL);
if (status === 'granted') {
this.setState({ hasCameraRollPermission: true });
this.getPhotos();
}
}
}
}
onTabPress = async (mode = 'photo', headerTitle = I18n.t('Take.tab2')) => {
const { flashMode } = this.state;
const { navigation } = this.props;
if (mode !== 'library') {
this.setState({
mode,
flashMode: (mode === 'photo') ? flashMode : Camera.Constants.FlashMode.off,
});
navigation.setParams({
headerTitle,
});
} else {
const permissions = Permissions.CAMERA_ROLL;
const { status } = await Permissions.askAsync(permissions);
if (status) {
const photo = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [1, 1],
});
if (!photo.cancelled) {
navigation.push('TakePublish', { mode: 'photo', photo });
}
}
}
}