2.1.1 • Published 3 years ago

@gorhom/sticky-item v2.1.1

Weekly downloads
35
License
MIT
Repository
github
Last release
3 years ago

npm npm npm

An interactive sticky item inspired by Facebook Stories.


Installation

yarn add @gorhom/sticky-item
# or
npm install @gorhom/sticky-item

Also, you need to install react-native-reanimated, react-native-gesture-handler & react-native-svg, and follow theirs installation instructions.

Usage

...
import StickyItemFlatList from '@gorhom/sticky-item';

// dummy data
const data = [...Array(20)]
  .fill(0)
  .map((_, index) => ({ id: `item-${index}` }));

// configs
const ITEM_WIDTH = 90;
const ITEM_HEIGHT = 150;
const STICKY_ITEM_WIDTH = 24;
const STICKY_ITEM_HEIGHT = 24;
const STICKY_ITEM_BACKGROUNDS = ['#222', '#000'];
const SEPARATOR_SIZE = 8;
const BORDER_RADIUS = 10;

const StickyItemView = ({
  x,
  threshold,
  itemWidth,
  itemHeight,
  stickyItemWidth,
  stickyItemHeight,
  separatorSize,
  isRTL,
}) => {

  const amazingAnimation = {
    // here you add your custom interactive animation
    // based on the animated value `x`
  }

  return <Animated.View style={amazingAnimation} />
}

const App = () => {
  // methods
  const handleStickyItemPress = () => Alert.alert('Sticky Item Pressed');

  // render
  const renderItem = ({ item, index}) => (
    <View
      key={`item-${index}`}
      style={{
        backgroundColor: 'red',
        width: ITEM_WIDTH,
        height: ITEM_HEIGHT,
      }}
    />
  )
  return (
    <StickyItemFlatList
      itemWidth={ITEM_WIDTH}
      itemHeight={ITEM_HEIGHT}
      separatorSize={SEPARATOR_SIZE}
      borderRadius={BORDER_RADIUS}
      stickyItemWidth={STICKY_ITEM_WIDTH}
      stickyItemHeight={STICKY_ITEM_HEIGHT}
      stickyItemBackgroundColors={STICKY_ITEM_BACKGROUNDS}
      stickyItemContent={StickyItemView}
      onStickyItemPress={handleStickyItemPress}
      data={data}
      renderItem={renderItem}
    />
  )
}

export default App

Props

namedescriptionrequiredtypedefault
itemWidthItem's width.YESnumber
itemHeightItem's height.YESnumber
separatorSizeFlatList's separator width, * if you provide ItemSeparatorComponent, you will need to set separatorSize.NO*number10
borderRadiusItem & sticky border radius.NOnumber15
stickyItemActiveOpacitySticky item's active opacity.YESnumber0.25
stickyItemWidthSticky item's width.YESnumber
stickyItemHeightSticky item's height.YESnumber
stickyItemBackgroundColorsSticky item's two background colors, one when sticky item is extended another when it's minimize.YESstring[]
stickyItemContentSticky item's content component.YESReactNode
isRTLFlatList' layout direction.NObooleanfalse
onStickyItemPressCallback when sticky item gets pressed.NOfunction
...FlatList PropsReact Native FlatList props.NOFlatList

To Do

  • Write a detailed step-by-step instruction to create sticky interactive animation.
  • Add more examples.
  • Add vertical support ?.

Author

License

MIT

Liked the library? 😇


2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago