Skip to content

How create permissions for react native when on click necessary module ? #15358

@boga01

Description

@boga01

I'm new to react native. I wrote the following code to call a function, if a user clicks on a camera.In addition I've a camera module how to call camera module on this partition at code.Code is run but it is call function while project starting,I want to click camera button and ask user camera options allow or deny question.I referenced yonahfrostproject esspecially example.js file I focused on but I don't understand it.

render () {
return (<TouchableOpacity onPress={this.openCamera}> 
<View> ???  </View> 
</TouchableOpacity> 
   
     )
  }

Plus my full code is here;

const permission = require('react-native-permissions')
import React , { Component } from 'react'
import {
StyleSheet,
TouchableHighlight,
Text,
View,
Alert,
AppState,
Platform,
AppRegistry,
Button,
TouchableOpacity,
} from 'react-native'

interface Props {
names: string[]
}

interface PermissionsState {
status: PermissionStatus
}

type PermissionStatus = 'granted' | 'denied' | 'never_ask_again' | ''

class Permissions {
static request(arg0: any): any {
    throw new Error('Method not implemented.')
}
static RESULTS: any
static PERMISSIONS: any
openCamera: any
public async requestCameraPermission() {
    try {
        const granted = await Permissions.request(
            Permissions.PERMISSIONS.CAMERA,
        )
        if (granted === Permissions.RESULTS.GRANTED) {
            // console.log("kamerayı kullanabilirsiniz")
        } else {
            // console.log('kamerayı kullanamazsınız')
        }
    } catch (err) {
        // console.warn(err)
    }
    
}
render () {
return (<TouchableOpacity onPress={this.openCamera}> 
<View> <Text>openCamera</Text> </View> 
</TouchableOpacity> 
   
    )
}

}

export default new Permissions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions