npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-motion-splash

v1.0.1

Published

Motional splash screen animations for React Native

Downloads

4

Readme

Table of Contents

  1. Installation
    1. iOS
    2. Android
  2. Usage
    1. Basic usage
    2. Animation types
    3. Advanced
  3. Compare with other libraries
  4. Demo
  5. Thanks

Installation

With npm: $ npm install react-native-motion-splash --save

With yarn: $ yarn add react-native-motion-splash

iOS

First step

First, run the following command to install Pods for iOS:

cd ios && pod install

Next open your project in Xcode, and add a image set, and set the name for it whatever you want (Eg: in the image below its name is Logo). This image will be the main image which will be animated later:

Second step

Next open LaunchScreen.xib to setup a splash screen, this screen will be shown at the very first time when you app runs. First press CMD + Shift + L to show list of components, then choose an Image View and drag and drop it under the root View.

Then select the image view in the hierarchy and set the image for it:

Next add constraints to the image like so:

Next select the root view and set background color for it by selection Background:

After all you should have this:

Third step

Next, open AppDelegate.m, and to function didFinishLaunchingWithOptions the following right before return YES:

#import "MotionSplash.h"

// Add below lines to didFinishLaunchingWithOptions

UIImage *img = [UIImage imageNamed:@"Logo"]; // the name of your image
CGSize iconInitialSize = CGSizeMake(70, 70); // (width, height) of your icon
NSString *backgroundColor = @"#0573ff";
[MotionSplash initWithIconImage:img iconInitialSize:&iconInitialSize backgroundColor:backgroundColor  inRootView:rootView];

Note:

  • iconInitialSize: must match the size you setup in second step to perform best animation visualization
  • backgroundColor: should also match the color of the root view you setup in second step in LaunchScreen.xib (you can use Digital Color Meter built-in on Mac to check Hexa color code)

Android

Open android/build.gradle and set minSdkVersion to 21.

Add you icon to android/app/src/main/res/mipmap, you should add the icon to all supported dimensions.

Create colors.xml in android/app/src/main/res/values. And add the following content:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="backgroundColor">#33B5E5</color>
    <!-- you can choose whatever color you want -->
</resources>

Next, create android/app/src/main/res/values/background_splash.xml with the following content:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/backgroundColor"
        android:gravity="fill" >
    </item>

    <item
        android:id="@+id/logo_splash"
        android:gravity="center"
        android:height="70dp"
        android:width="70dp"
        >
        <bitmap
            android:gravity="fill"
            android:src="@mipmap/logo"
            />
    </item>

</layer-list>

Next, open android/app/src/main/res/values/styles.xml, and change to following:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="android:textColor">#000000</item>
    </style>


    <!-- Add this section -->
    <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:background">@drawable/background_splash</item>
        <item name="android:windowFullscreen">true</item>
    </style>

</resources>

Now add SplashActivity.java in android/app/src/main/java with the following content:

package com.example;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();

    }
}

Next open MainActivity.java and add the following:

import com.reactlibrary.MotionSplash;
...
@SuppressLint("ResourceType")
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Size iconInitialSize = new Size(70, 70);
  String backgroundColor = getResources().getString(R.color.backgroundColor);
  MotionSplash.init(MainActivity.this, R.drawable.background_splash, R.id.logo_splash, iconInitialSize, backgroundColor);
}

Finally, open android/app/src/main/java/AndroidManifest.xml, and update applcation to:

<application>
  <activity
    android:name=".SplashActivity"
    android:theme="@style/SplashTheme"

    >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity
      android:name=".MainActivity"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
      android:label="@string/app_name"
      android:launchMode="singleTask"
      android:windowSoftInputMode="adjustResize">
  </activity>
  ...
....

Usage

Basic

import MotionSplash from 'react-native-motion-splash'

componentDidMount() {
  MotionSplash.animate() // use Twitter reveal animation as default
}

//or
useEffect(() => {
  MotionSplash.animate()
}, [])

Animation types

There are several of animations you choose from, just pass the animation name into MotionSplash.animate('animationType')

Twitter

Its the default animation that Twitter use for their app. If animationType is not set it will default to this one.

HeartBeat

HeartBeat like animation, unlike the other animations, this special animation allows you to continue to animate until a function its called. This could be more entertaining to the user than having a quick launch and waiting on a spinning wheel if the app needs to fetch more data.

To use the Heartbeat animation you should use MotionSplash.animate('HeartBeat') as normal and then proceed with your network or background job. When you are done, just call:

MotionSplash.hide()

And the splashview should dismiss:

To set the number of minimum beats per round trip, use:

MotionSplash.setMinimumBeats(3);

Rotate Out

Similar to the Twitter one but rotating while zooming out.

MotionSplash.animate('RotateOut')

Pop and Zoom Out

Pop the view a couple of times and zoom out.

MotionSplash.animate('PopAndZoomOut')

Squeeze and Zoom Out

Squeeze the view and zoom out.

MotionSplash.animate('SqueezeAndZoomOut')

Swing and Zoom Out

Swings the view and zoom out.

MotionSplash.animate('SwingAndZoomOut')

Wobble and Zoom Out

Wobbles the view and zoom out.

MotionSplash.animate('WobbleAndZoomOut')

Advanced

Using background image

If you want to add a background image after the animated icon instead of using background color. Do the following:

Go to ios/YourProject/AppDelegate.m and change to:

UIImage *img = [UIImage imageNamed:@"Logo"];
UIImage *backgroundImage = [UIImage imageNamed:@"Background"]; // NOTE this line, here is the name of your background image
CGSize iconInitialSize = CGSizeMake(70, 70);
[MotionSplash initWithIconImage:img iconInitialSize:&iconInitialSize backgroundImage:backgroundImage  inRootView:rootView];

Go to android/app/src/main/res/drawable/background_splash.xml and change to the following:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

  <item
    android:drawable="@color/backgroundColor"
    android:gravity="fill" >
  </item>

  <!-- Your background image here -->
  <item
    android:id="@+id/logo_background"
    android:gravity="center"
  >
    <bitmap
      android:gravity="fill"
      android:src="@mipmap/background"
    />
  </item>

  <item
    android:id="@+id/logo_splash"
    android:gravity="center"
    android:height="70dp"
    android:width="70dp"
  >
    <bitmap
      android:gravity="fill"
      android:src="@mipmap/logo"
    />
  </item>
</layer-list>

Then go to android/app/src/main/java/MainActivity.java and change like follow:

@SuppressLint("ResourceType")
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Size iconInitialSize = new Size(70, 70);
  MotionSplash.init(MainActivity.this, R.drawable.background_splash, R.id.logo_splash, iconInitialSize, R.id.logo_background);
}

// Note the "R.id.logo_background" above, that must match the id in the drawable xml

Now reload your app to see the change

Icon tint color

To change the tint color of the animated icon or background image, use the following:

MotionSplash.useCustomColor(true, 'red');
// true will be applied to the animated icon
// false applied for the background image (if set)

Compare with other libraries

  • react-native-boot-splash requires you to use Storyboard for iOS, and their tool is also do some configurations for you in order to make it work (Eg: changing Info.plist). So in the future if you don't want to use that library and want to go back to the original structure, it's maybe hard
  • on iOS both react-native-boot-splash and react-native-splash-screen idea is animate the whole splash screen, this make it's impossible in cases you have more than 1 objects on the splash screen and you just want animate the center one (for example)

By creating splash screen manually using native code under the hood, react-native-motion-splash have full control of how the splash screen should be shown, how it should be animated. That's why RNMotionSplash can perform more animations.

Demo

A fully working demo is located at example folder

Thanks

Big thanks to Pixel16 of his great work that inspires me to create this library.