2.0.5 • Published 4 years ago

react-native-animated-splash-screen v2.0.5

Weekly downloads
612
License
MIT
Repository
github
Last release
4 years ago

Animated splash screen for Android and iOS. It is based on Implementing Twitter’s App Loading Animation in React Native topic from RN. This use an Image instead of MaskedView to work on both platforms.

license Version npm GitHub issues PRs Welcome runs with expo

GitHub followers GitHub stars

Features

  • Custom background color.
  • Custom background image.
  • Custom logo.
  • Custom logo size.
  • It works both: Expo and Pure React Native. (Thanks to WrathChaos!)

Installation

yarn add react-native-animated-splash-screen or npm install --save react-native-animated-splash-screen

Usage

import AnimatedSplash from "react-native-animated-splash-screen";

render() {
    return (
      <AnimatedSplash
        translucent={true}
        isLoaded={this.state.isLoaded}
        logoImage={require("./assets/logo.png")}
        backgroundColor={"#262626"}
        logoHeight={150}
        logoWidth={150}
      >
        <App />
      </AnimatedSplash>
    );
  }

Props

NameDescriptionTypeRequiredDefault Value
isLoadedCondition to show children component and finish the animation.Booleanfalse
backgroundColorSplash screen background color.String#f00 '#f00'
logoImageSplash screen logo image.Objectnull
logoWidthLogo image width in px.Number150
logoHeightLogo image height in px.Number150
childrenChildren to render inside this component.Nodenull
preloadCondition to load children component while wait isLoaded prop be True.Booleantrue
disableBackgroundImageDisable the background imageBooleanfalse
translucentWhen translucent is set to true, the app will draw under the status bar. Example: here!Booleanfalse
customComponentAdd a logo component instead of a logo image.React Componentnull

Example with React Navigation

const AppNavigator = createStackNavigator(
  {
    home: {
      screen: HomeScreen,
      navigationOptions: {
        header: null,
      },
    },
    dashboard: {
      screen: DashboardScreen,
      navigationOptions: {
        title: "Dashboard",
      },
    },
  },
  {
    initialRouteName: "home",
  }
)

const Container = createAppContainer(AppNavigator)

class App extends React.Component {
  state = {
    isLoaded: false,
  }

  async componentDidMount() {
    await loadAsync()
    this.setState({ isLoaded: true })
  }

  render() {
    return (
      <AnimatedSplash
        translucent={true}
        isLoaded={this.state.isLoaded}
        logoImage={require("./assets/logo.png")}
        backgroundColor={"#262626"}
        logoHeight={150}
        logoWidth={150}
      >
        <Container />
      </AnimatedSplash>
    )
  }
}

export default App

Example with React Navigation (setting isLoaded inside a screen of navigator)

Navigator

const AppNavigator = createSwitchNavigator(
  {
    home: {
      screen: props => (
        <HomeScreen {...props} setAppLoaded={props.screenProps.setAppLoaded} />
      ),
    },
    dashboard: { screen: DashboardScreen },
  },
  {
    initialRouteName: "home",
  }
)

const Container = createAppContainer(AppNavigator)

class App extends React.Component {
  state = {
    isLoaded: false,
  }

  setAppLoaded = () => {
    this.setState({ isLoaded: true })
  }

  render() {
    return (
      <AnimatedSplash
        translucent={true}
        isLoaded={this.state.isLoaded}
        logoImage={require("./assets/logo.png")}
        backgroundColor={"#262626"}
        logoHeight={150}
        logoWidth={150}
      >
        <Container screenProps={{ setAppLoaded: this.setAppLoaded }} />
      </AnimatedSplash>
    )
  }
}

export default App

HomeScreen

class HomeScreen extends React.Component {

...

  async componentDidMount() {
    await loadAsync();
    this.props.setAppLoaded();
  }

...

}

export default HomeScreen

Example of translucent prop

Author

Fabio Freitas

License

MIT