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

China☆狼群 提交于 2019-11-30 12:13:27

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.

Javier Hernández Sansalvador

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!