react-native-immediate-phone-call not working

590 views Asked by At

I am writing app that uses react-native-immediate-phone-call and by pressing Pressable component I need to call function from that module.

import RNImmediatePhoneCall from 'react-native-immediate-phone-call';

export default function App() {
    const [getNumber, setNumber] = useState('');

    function makeCall() {
        console.log('dialing');
        return () => RNImmediatePhoneCall.immediatePhoneCall(getNumber);
    }
    ...
    return (
        ...
        <Pressable onPress={()=>makeCall()}>
            <Image source={require('./assets/phone-call.png')}/>
        </Pressable>
        ...
    );
}

Console log is displayed into terminal with Metro Bunler but return does not execute somehow. I am newbie into js and react. How function and function call should like?

2

There are 2 answers

4
Sanka Sanjeeva On BEST ANSWER

At that moment getNumber == ''

So, I think RNImmediatePhoneCall.immediatePhoneCall('') do nothing.

Also, try with this (will be work when getNumber has a value)

function makeCall() {
    console.log('dialing');
    RNImmediatePhoneCall.immediatePhoneCall(getNumber);
}

EDIT:

Still, nothing happens, I find a solution from their issues

First, check your phone permission for call: In the AndroidManifest.xml Then add the following lines

<uses-permission android:name="android.permission.CALL_PHONE" />

If still not working, do follow the steps

In settings.gradle after rootProject.name = 'YOUR_PROJ_NAME' add the following line

include ':react-native-immediate-phone-call', ':app'

In build.gradle Inside the dependencies section insert the following line

implementation project(':react-native-immediate-phone-call')

In AndroidManifest.xml add the following line with all other user-permissions

<uses-permission android:name="android.permission.CALL_PHONE" />

In MainActivity.java import this

import com.github.wumke.RNImmediatePhoneCall.RNImmediatePhoneCallPackage;

inside the class, MainActivity add the following override (include the "@override" for some reason it's not in the same block with the rest of the code)

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    
    RNImmediatePhoneCallPackage.onRequestPermissionsResult(requestCode, permissions, grantResults); // very important event callback
    
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

}
0
Richy On

You are not calling the function but returning it so you get a function back.

Just change the following:

return () => RNImmediatePhoneCall.immediatePhoneCall(getNumber);

to:

RNImmediatePhoneCall.immediatePhoneCall(getNumber);