Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the FB login button text (react-native-fbsdk)

Tags:

I am using react-native-fbsdk. How can I change the fb login button text from 'Login with facebook' to 'Continue with fb'?

The component looks like this, and I can't find a way to change it:

<LoginButton           style={styles.facebookbutton}           readPermissions={["public_profile", 'email']}           onLoginFinished={             (error, result) => {               if (error) {                 console.log("login has error: " + result.error);               } else if (result.isCancelled) {                 console.log("login is cancelled.");               } else {                 AccessToken.getCurrentAccessToken().then(                   (data) => {                     console.log(data);                     console.log(data.accessToken.toString());                   }                 )               }             }           }           onLogoutFinished={() => alert("logout.")}/> 
like image 769
perrosnk Avatar asked Jan 25 '17 11:01

perrosnk


People also ask

How do I integrate Facebook Login With react?

Run our React App to login with FacebookGo to https://localhost:3000 and you can see the browser displays a button to Login With Facebook as below. Click the `Login with Facebook` button then it will be a Facebook login dialog pop up. Enter your email address or phone number and password. Then press button “Log in”.

Is Facebook still supporting react native?

As of January 19, 2021, Facebook React Native SDK will no longer be officially supported by Facebook. Please visit our blog post for more information and Github for React Native going forward.


2 Answers

The easiest way is to upgrade the SDK to 4.19.0:

The LoginButton UI is changed in 4.19.0. Instead of "Log in with Facebook", the button now displays "Continue with Facebook". The button color is changed to #4267B2 from #3B5998. The button height is decreased from 30dp to 28dp due to use of smaller font size and paddings around a larger Facebook logo.

The interface for using LoginButton remains the same. Please take time to ensure the updated LoginButton does not break your app's UX

However, if you're after customising the text so it literally says "Continue with fb" you'd need to recreate the Button component, and use it to trigger the Login Manager, i.e.:

import React, { Component } from 'react' import { Button } from 'react-native'  import { LoginManager } from 'react-native-fbsdk'  export default class Login extends Component {   handleFacebookLogin () {     LoginManager.logInWithReadPermissions(['public_profile', 'email', 'user_friends']).then(       function (result) {         if (result.isCancelled) {           console.log('Login cancelled')         } else {           console.log('Login success with permissions: ' + result.grantedPermissions.toString())         }       },       function (error) {         console.log('Login fail with error: ' + error)       }     )   }   render () {     return (       <Button         onPress={this.handleFacebookLogin}         title="Continue with fb"         color="#4267B2"       />     )   } } 

That way also gives you full control over the UI which is particularly handy if you have your own components library, or use a ready made one like NativeBase.

like image 115
designorant Avatar answered Jan 27 '23 04:01

designorant


You can use your custom function and add Login Manager into your function.

Here is the code

import { LoginManager } from "react-native-fbsdk";  const loginWithFacebook = () => {   LoginManager.logInWithPermissions(["public_profile", "email"]).then(     function(result) {       if (result.isCancelled) {         console.log("==> Login cancelled");       } else {         console.log(           "==> Login success with permissions: " +             result.grantedPermissions.toString()         );       }      },      function(error) {       console.log("==> Login fail with error: " + error);      }    ); } 

Call it in your custom button

<TouchableOpacity onPress={() => loginWithFacebook()}>   <Text> Login With Facebook </Text>           </TouchableOpacity> 
like image 43
Channat Tem Avatar answered Jan 27 '23 02:01

Channat Tem