0.10.0 • Published 6 months ago

roko-tab-indicator v0.10.0

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

roko-group-buttons

Simple animated group button

Installation

npm install roko-tab-indicator

Usage

import { Animated, Dimensions, Image, StyleSheet, View } from 'react-native';
import React, { useCallback, useRef } from 'react';
import DummyList from './data/DummyList';
import { TabIndicator } from 'roko-tab-indicator';

const options = ['Kroni', 'eshte', 'djale i mire'];

const { width, height } = Dimensions.get('screen');

const App = ({}) => {
  // #region REFERENCES
  const scrollX = useRef(new Animated.Value(0)).current;
  const listRef = useRef<Animated.FlatList<string> | null>(null);
  // #endregion
  // #region FUNCTIONS
  const onItemPress = useCallback((index) => {
    listRef.current?.scrollToOffset({ offset: index * width, animated: true });
  }, []);
  // #endregion
  return (
    <View style={styles.root}>
      <Animated.FlatList
        ref={listRef}
        onScroll={Animated.event(
          [{ nativeEvent: { contentOffset: { x: scrollX } } }],
          { useNativeDriver: false }
        )}
        pagingEnabled
        horizontal
        data={DummyList}
        renderItem={({ item }) => (
          <View style={{ height, width }}>
            <Image
              source={{ uri: item }}
              style={{ ...StyleSheet.absoluteFillObject }}
            />
            <View style={styles.backDrop} />
          </View>
        )}
      />
      <View style={styles.tabContainer}>
        <TabIndicator
          {...{
            options,
            onItemPress,
            scrollX,
            theme: {
              primary: 'rgba(0,0,0,0.8)',
              onPrimary: 'white',
              background: 'transparent',
              onBackground: 'black',
            },
          }}
        />
      </View>
    </View>
  );
};

export default App;

App.displayName = 'App';

const styles = StyleSheet.create({
  root: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  tabContainer: {
    padding: 16,
    position: 'absolute',
    top: 80,
    start: 16,
  },
  backDrop: {
    backgroundColor: 'rgba(0,0,0, 0.3)',
    ...StyleSheet.absoluteFillObject,
  },
});

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

0.10.0

6 months ago

0.9.0

6 months ago

0.8.0

6 months ago

0.5.0

7 months ago

0.6.0

6 months ago

0.4.0

8 months ago

0.3.0

8 months ago

0.2.3

8 months ago

0.2.2

8 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.0

8 months ago