I'm new at react native and typescript.I wanna create permissions module for my react native project and I seperated two links at below Yonah's project and Facebook's permissions project
Additionaly
npm install ,npm start , yarn run build --watch and react-native run-android
command running smoothly but permission module dont use it ,I dont present this module add my project.
And my trying code at below :
const permission = require('react-native-permissions')
import React from 'react'
import {
StyleSheet,
TouchableHighlight,
Text,
View,
Alert,
AppState,
Platform,
PermissionsAndroid,
} from 'react-native'
interface Props {
names: string[];
}
interface PermissionsState {
status: PermissionStatus;
}
type PermissionStatus = 'granted' | 'denied' | 'never_ask_again' | ''
export class permissions extends React.Component<Props, PermissionsState> {
constructor(props: Props, context: any)
// tslint:disable-next-line:brace-style
{
super(props, context)
this.state = {
status: '',
}
}
public render()
// tslint:disable-next-line:brace-style
{
return <View> a </View>
}
}
async function requestCameraPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// console.log("kameray谋 kullanabilirsiniz")
} else {
// console.log('kameray谋 kullanamazs谋n谋z')
}
} catch (err) {
// console.warn(err)
}
}
export default permission
I'm not sure what the problem here is. What error do you get?
I think the problem He might have, and the problem I have, is module resolution with typescript (tslint hints for Typescript linter...)
As a reminder, here is Typescript module resolution : https://www.typescriptlang.org/docs/handbook/module-resolution.html
I was trying to import react-native-permissions from a Typescript file like this
import Permissions from 'react-native-permissions';
and I was getting an error : [ts] cannot find module 'react-native-permissions'
I think it's because Typescript does read package.json main entry as being index, and so looks up for 'index.js'.
It doesn't switch between index.ios.js and index.android.js as react-native does.
My fix for that was to add a index.js file, importing both platform specific index files (index.ios.js and index.android.js)
@wynch, that's right
In my project:
import { Platform } from 'react-native';
import IOSPermissions = require('react-native-permissions/index.ios');
import AIPermissions = require('react-native-permissions/index.android');
const Permissions = IOSPermissions ? Platform.OS === 'ios' : AIPermissions;
export = Permissions;
It has been fixed in https://github.com/yonahforst/react-native-permissions/releases/tag/1.0.2
@zoontek, could you publish these changes?
@monolithed I would love it, but I don't have the publish rights on npm. You have to ping @yonahforst for that :)
@monolithed published 1.0.2 to npm.
@zoontek - just granted you publish rights 馃槃馃
i am trying to convert import permissions from expo to just react-native in my existing app. can i use these permissions? if yes, then which files do i need to copy.
Most helpful comment
@wynch, that's right
In my project: