Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-skeleton-simpler

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-skeleton-simpler

A simple and fully customizable React Native component that implements a skeleton-like loader

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26
increased by136.36%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Skeleton Simpler

React Native Skeleton Simpler, a simple yet fully customizable component made to achieve loading animation in a Skeleton-style. Works in both iOS and Android.

  • React Native Skeleton Simpler

Installation

npm install react-native-skeleton-simpler

or

yarn add react-native-skeleton-simpler

Usage

  1. Import react-native-skeleton-content:
import {SkeletonSimpler} from 'react-native-skeleton-simpler';
  1. Once you create the SkeletonSimpler, you have three options:
  • Custom Layout : You provide a prop layout to the component specifying the size of the bones (see the Examples section below). Below is an example with a custom layout.

  • Custom Layout : You provide a prop SkeletonComponent recommended for complex layouts.

  • Child Layout (in Development): The component will figure out the layout of its bones with the dimensions of its direct children. :construction:

export default function Placeholder() {
  return (
    <SkeletonSimpler
      containerStyle={{ flex: 1, width: 300 }}
      isLoading={true}
      layout={[
        { width: 220, height: 20, marginBottom: 6 },
        {  width: 180, height: 20, marginBottom: 6 }
      ]}
    >
      <Text>Your content</Text>
      <Text>Other content</Text>
    </SkeletonSimpler>
  );
}
  1. Then simply sync the prop isLoading to your state to show/hide the SkeletonSimpler when the assets/data are available to the user.
export default function Placeholder () {
  const [loading, setLoading] = useState(true);
  return (
    <SkeletonSimpler
       containerStyle={{flex: 1, width: 300}}
        isLoading={isLoading}>
        {...otherProps}
    />
  )
}

Props

NameTypeDefaultDescription
isLoadingboolrequiredShows the Skeleton bones when true
layoutarray of objects[]A custom layout for the Skeleton bones
durationnumber1000 msDuration of one cycle of animation
containerStyleobjectflex: 1The style applied to the View containing the bones
SkeletonComponentReact.JSX.Elementnot requiredCustom Componente of skeleton, recommended for complex layouts.
themestring (light or dark)lightTheme of SkeletonSimpler and SkeletonItem
animatedConfigobject of Animated.TimingAnimationConfig{toValue: 1, duration: 1000, seNativeDriver: false, delay: 800}Configs of Animated.timing

Examples

1 - Customizing the layout of the bones (layout prop) :

export default function Placeholder () {
  return (
    <SkeletonContent
        layout={[
        // long line
        { width: 220, height: 20, marginBottom: 6 },
        // short line
        { width: 180, height: 20, marginBottom: 6 },
        ...
        ]}
        isLoading={true}>
        ...
    />
  )
}

2 - Customizing the layout with props SkeletonComponent :

2.1 import SkeletonSimpler and SkeletonItem

import {SkeletonSimpler, SkeletonItem} from 'react-native-skeleton-simpler';

2.2 Create your custom SKeleton component using SkeletonItem

const SkeletonComponent = () => (

      <View style={{ flexDirection: 'row',
                    alignItems: 'center',
                    marginTop: 10,
                    justifyContent: 'space-between',
                }}>
                <View>
                    <SkeletonItem
                        style={[
                            styles.common,
                            {
                                width: 150,
                                height: 15,
                                borderRadius: 10,
                                marginTop: 10,
                            },
                        ]}
                    />
                    <SkeletonItem
                        style={[
                            styles.common,
                            {
                                width: 200,
                                height: 15,
                                borderRadius: 10,
                                marginTop: 10,
                            },
                        ]}
                    />
                </View>
                <View
                    style={{
                        flexDirection: 'row',
                        alignItems: 'center',
                    }}>
                    <SkeletonItem
                        style={[
                            styles.circle,
                            {marginLeft: 10, width: 40, height: 40},
                        ]}
                    />
                </View>
            </View>
) 

2.3 Pass your custom component in SkeletonComponent prop

    
  export const SkeletonSimplerExample = () => {
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    setTimeout(() => setLoading(false), 3000);
  }, []);

  return (
    <SkeletonSimpler loading={loading} SkeletonComponent={SkeletonLoader}>
      <View>
        <Text>Your children</Text>
      </View>
    </SkeletonSimpler>
  );
};

You can find this complete example here

Keywords

FAQs

Package last updated on 30 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc