Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.3 kB
5
Indexable
Never
import React, { useState } from 'react';
import {
  View,
  Text,
  StyleSheet,
  Image,
  ScrollView,
  FlatList,
} from 'react-native';
import Collapsible from 'react-native-collapsible';

const App = () => {
  const [isCollapsed, setIsCollapsed] = useState(false);

  // Dummy data for FlatList
  const DATA = Array.from({ length: 50 }, (_, i) => `Item ${i + 1}`);

  const renderItem = ({ item }) => <Text style={styles.item}>{item}</Text>;

  return (
    <View style={styles.container}>
      <ScrollView
        onScroll={(event) => {
          const yOffset = event.nativeEvent.contentOffset.y;
          setIsCollapsed(yOffset > 50);
        }}
        scrollEventThrottle={16}
      >
        <Collapsible collapsed={isCollapsed}>
          <Image
            source={{ uri: 'https://placekitten.com/400/200' }} // Replace with your image URL
            style={styles.image}
          />
        </Collapsible>
        <FlatList
          data={DATA}
          renderItem={renderItem}
          keyExtractor={(item) => item}
        />
      </ScrollView>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  image: {
    width: '100%',
    height: 200,
  },
  item: {
    padding: 20,
    borderBottomWidth: 1,
    borderBottomColor: '#ccc',
  },
});

export default App;
Leave a Comment