23

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.")}/>
perrosnk
  • 835
  • 2
  • 13
  • 23
  • afaik it is not possible to change the next in the official android loginbutton plugin, so i assume it´s not possible with the react native fbsk either. you should not change the text anyway, users should always know for sure what they can expect: a "login". – andyrandy Jan 25 '17 at 11:39
  • Here (https://developers.facebook.com/docs/facebook-login/userexperience) sats you can and possibly should change it, because it converts better. Please check the button design section – perrosnk Jan 25 '17 at 13:12
  • you may need to create your own login button then – andyrandy Jan 25 '17 at 13:16
  • I have the opposite problem... i have continue with facebook, which by the way doesn't even fit.... to login with FB. – Fab Feb 01 '17 at 22:09
  • Same problem here. How to customize this button ? Thanks – Arkon Feb 07 '17 at 22:37

3 Answers3

43

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.

designorant
  • 2,344
  • 14
  • 25
  • 1
    Do you know how to request both read and publish permissions with LoginManager? – vma May 30 '17 at 20:15
  • I guess you would have to chain `LoginManager.logInWithReadPermissions` and `LoginManager.logInWithPublishPermissions` in a promise or something but bear in mind users don't like to be asked for a ton of permissions before they ever get to use the app. It's a common practice to request an absolute minimum at login, and then ask for more permissions in context as they use the app. See: https://developers.facebook.com/docs/facebook-login/best-practices#context – designorant May 31 '17 at 10:52
  • @designorant method call is nor working inside fb method. – Rushi trivedi Jun 29 '18 at 12:39
  • Do use `LoginManager.logInWithPermissions()` instead of `LoginManager.logInWithReadPermissions()` – michael_vons Mar 11 '20 at 20:19
5

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>
Channat Tem
  • 61
  • 1
  • 5
-6

For those who want to customize the button, I have not found the way to change its text, but you can change the width and height of this button in node-modules/react-native-fbsdk/js/FBLoginButton.js.

const styles = StyleSheet.create({
  defaultButtonStyle: {
    height: 30,
    width: 195,
  },
});

I have written here a value of 195 so that the 'Continue with Facebook' text fits well.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
  • 13
    You shouldn't be modifying `node_modules` as they are managed by npm/yarn and will get replaced with any update/upgrade/reinstall. – designorant May 31 '17 at 10:15
  • Avoid using fixed values and also, avoid modifying node_modules, you should use comments for answers like this – Gabriel Belini Jun 11 '19 at 19:08