Coder Social home page Coder Social logo

baham-task's Introduction

import { FlatList, ScrollView, StyleSheet, Text, View, SectionList,Pressable, Button } from 'react-native'; import AppHeader from './AppHeader'; import AppFooter from './AppFooter'; import { useState } from 'react';

const allVehicles = [ { "type": "Sedan", "data": [ {'id': 1, 'name': "Honda City", 'capacity': 4 }, {'id': 2, 'name': "Honda Civic", 'capacity': 4 }, {'id': 3, 'name': "Honda Accord", 'capacity': 5 }, {'id': 4, 'name': "Toyota Corolla", 'capacity': 4 }, {'id': 5, 'name': "Toyota Camry", 'capacity': 4 }, {'id': 6, 'name': "Toyota Prius", 'capacity': 4 }, ], }, { "type": "Hatch back", "data": [ {'id': 7, 'name': "Honda Fit", 'capacity': 5 }, {'id': 8, 'name': "Suzuki Mehran", 'capacity': 4 }, {'id': 9, 'name': "Suzuki Alto", 'capacity': 4 }, {'id': 10, 'name': "Suzuki Cultus", 'capacity': 4 }, {'id': 11, 'name': "Suzuki Wagon R", 'capacity': 4 }, {'id': 12, 'name': "Suzuki Swift", 'capacity': 4 }, {'id': 13, 'name': "Toyota Vitz", 'capacity': 4 }, {'id': 14, 'name': "Toyota Passo", 'capacity': 4 }, {'id': 15, 'name': "Hyundai Santro", 'capacity': 4 }, ] }, { "type": "SUV", "data": [ {'id': 16, 'name': "Hyundai Tucson", 'capacity': 5 }, {'id': 17, 'name': "Kia Sportage", 'capacity': 5 }, {'id': 18, 'name': "Toyota Hilux", 'capacity': 9 }, {'id': 19, 'name': "Toyota Land Cruiser", 'capacity': 6 }, ] }, { "type": "Motorcycle", "data": [ {'id': 20, 'name': "Kawasaki GTO110", 'capacity': 2 }, {'id': 21, 'name': "Suzuki GSX125", 'capacity': 2 }, {'id': 22, 'name': "Suzuki GS150", 'capacity': 2 }, {'id': 23, 'name': "Yamaha YBR125", 'capacity': 2 }, ] }, { "type": "Van", "data": [ {'id': 24, 'name': "Suzuki Bolan", 'capacity': 6 }, {'id': 25, 'name': "Toyota Hiace", 'capacity': 13 },
{'id': 26, 'name': "Hyundai Shehroz", 'capacity': 10 }, {'id': 27, 'name': "Kia Grand Carnival", 'capacity': 7 }, ] } ]

export default function App() {

const [showMenu,setShowMenu] = useState(false)

const onMenuPress = () => {setShowMenu(!showMenu)};

// Render the headers of section. Note that the input prop is section and we're using 'type' attribute inside const renderSectionHeader = ({ section }) => { return ({section.type}); };

// Render each menu item const renderVehicleModelItem = ({ item }) => { return ( {item.name} ({item.capacity}) ); }

// Separator separates items. We're only using an empty view with border for now const itemSeparatorComponent = () => <View style={{ borderColor: 'black', borderStyle: "dotted", borderWidth: 1 }}>;

return ( // Demo: Section List {/* Attach header component */}

  {!showMenu && 
  <Text>
    Baham is a learning Project
  </Text>
  }

  {showMenu &&
    <View style={styles.mainContainer}>
      <SectionList 
      sections={allVehicles}
      renderItem={renderVehicleModelItem}
      renderSectionHeader={renderSectionHeader}
      ItemSeparatorComponent={itemSeparatorComponent}
      keyExtractor={(item, index) => item.id * (item.id + index)}
      />
    </View>
    }

  <Pressable onPress={onMenuPress}>
    <Text>{showMenu ? "<<< Hide Menu >>>" : "<<< Show Menu >>>"}</Text>
  </Pressable> 

  
  
  {/* Attach footer component */}
  <AppFooter />
</View>

); }

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'space-between', backgroundColor: 'gold' }, mainContainer: { flex: 1, backgroundColor: 'white' }, menuItem: { textAlign: 'center', margin: 12, fontSize: 16, color: 'maroon' } });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.