1.0.5 • Published 9 months ago

react-native-skeleton-simpler v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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.

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

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago