Rendered FlatList is not scrollable in react native

Basically i have a react native tab to search for an avalaible room based on the user input, after the user submit their input, the app will render a flat list of the avalaible rooms. The problem is after i tried to submit my input, the flat list actually renders but i can’t scroll down to see the rendered flat list, do you guys have any idea to fix it? By the way here’s my code (I partially use indonesian language for the code so just ignore any words you can’t understand):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import {
StyleSheet,
View,
SafeAreaView,
Text,
TextInput,
TouchableWithoutFeedback,
Keyboard,
Button,
FlatList,
ScrollView,
} from "react-native";
import { useEffect, useState } from "react";
import DateTimePicker from "@react-native-community/datetimepicker";
import { Dropdown } from "react-native-element-dropdown";
import { format } from "date-fns";
const data = [
{ label: "Selasar", value: "selasar" },
{ label: "Kelas", value: "kelas" },
{ label: "Lab", value: "lab" },
];
export default function PinjamRuanganScreen() {
const [tanggal, setTanggal] = useState(new Date());
const [mulai, setMulai] = useState(new Date());
const [selesai, setSelesai] = useState(new Date());
const [jenis, setJenis] = useState(null);
const [kapasitas, setKapasitas] = useState(0);
const [searched, setSearched] = useState(false);
const [result, setResult] = useState([]);
const formatDate = (date) => {
return format(date, "yyyy-MM-dd");
};
const formatTime = (date) => {
const hours = date.getHours().toString().padStart(2, "0");
const minutes = date.getMinutes().toString().padStart(2, "0");
const formattedTime = `${hours}:${minutes}`;
return formattedTime;
};
const changeDate = ({ type }, selectedDate) => { if (type === "set") {
const currentDate = selectedDate;
setTanggal(currentDate);
}
};
const changeMulai = ({ type }, selectedDate) => { if (type === "set") {
const currentDate = selectedDate;
setMulai(currentDate);
}
};
const changeSelesai = ({ type }, selectedDate) => { if (type === "set") {
const currentDate = selectedDate;
setSelesai(currentDate);
}
};
const handleSubmit = async () => {
try {
const response = await fetch(
`http:(my-ip-address):4000/ruangan/cari-ruangan?jenis=${jenis}&tanggal=${formatDate(
tanggal
)}&mulai=${formatTime(mulai)}&selesai=${formatTime(
selesai
)}&kapasitas=${kapasitas}`
);
const data = await response.json();
setResult(data.ruanganTersedia);
setSearched(true);
console.log(result.length);
} catch (error) {
console.log(error);
}
};
return (
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
<SafeAreaView style={styles.container}>
<Text style={styles.label}>Tanggal peminjaman: </Text>
<DateTimePicker
value={tanggal}
mode="date"
onChange={changeDate}
style={styles.timePicker}
/>
<Text style={styles.label}>Dari jam: </Text>
<DateTimePicker
value={mulai}
mode="time"
onChange={changeMulai}
style={styles.timePicker}
/>
<Text style={styles.label}>Sampai jam: </Text>
<DateTimePicker
value={selesai}
mode="time"
onChange={changeSelesai}
style={styles.timePicker}
/>
<Dropdown
style={styles.dropdown}
maxHeight={300}
itemContainerStyle={{ width: 600 }}
data={data}
labelField={"label"}
valueField={"value"}
placeholder="Pilih jenis ruangan"
value={jenis}
onChange={(value) => setJenis(value.value)}
renderItem={(item) => {
return (
<View style={styles.item}>
<Text>{item.label}</Text>
</View>
);
}}
/>
<Text>Kapasitas:</Text>
<TextInput
style={styles.textInput}
keyboardType="numeric"
value={kapasitas}
onChangeText={setKapasitas}
/>
<Button title="Cari ruangan" onPress={handleSubmit} />
{!searched ? (
<Text>Hasil pencarian ruangan akan ditampilkan disini</Text>
) : result.length === 0 ? (
<>
<Text>
Tidak ada ruangan yang sesuai dengan kriteria yang anda inginkan
</Text>
</>
) : (
<View>
<FlatList
data={result}
renderItem={({ item }) => {
return (
<View style={styles.card}>
<Text style={styles.namaRuangan}>{item.nama}</Text>
<Text style={styles.detailRuangan}>{item.jenis}</Text>
<Text style={styles.detailRuangan}>{item.kapasitas}</Text>
<Text style={styles.detailRuangan}>{item.lantai}</Text>
</View>
);
}}
keyExtractor={(item) => item._id}
ItemSeparatorComponent={<View style={{ height: 24 }} />}
ListHeaderComponent={
<View style={{ marginTop: 20, marginBottom: 20 }}>
<Text
style={{
alignSelf: "center",
fontSize: 30,
fontWeight: "bold",
}}
>
Ruangan yang tersedia
</Text>
</View>
}
/>
</View>
)}
</SafeAreaView>
</TouchableWithoutFeedback>
);
}
const styles = StyleSheet.create({
container: {
padding: 24,
justifyContent: "center",
alignItems: "center",
},
dropdown: {
margin: 16,
height: 50,
alignSelf: "stretch",
borderBottomColor: "gray",
borderBottomWidth: 0.5,
},
item: {
padding: 17,
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
},
label: {
marginBottom: 10,
},
timePicker: {
marginBottom: 20,
},
textInput: {
borderWidth: 1,
borderStyle: "solid",
width: 50,
},
card: {
backgroundColor: "white",
padding: 16,
borderRadius: 8,
borderWidth: 1,
},
namaRuangan: {
fontSize: 30,
},
detailRuangan: {
fontSize: 24,
color: "#666666",
},
});
</code>
<code>import { StyleSheet, View, SafeAreaView, Text, TextInput, TouchableWithoutFeedback, Keyboard, Button, FlatList, ScrollView, } from "react-native"; import { useEffect, useState } from "react"; import DateTimePicker from "@react-native-community/datetimepicker"; import { Dropdown } from "react-native-element-dropdown"; import { format } from "date-fns"; const data = [ { label: "Selasar", value: "selasar" }, { label: "Kelas", value: "kelas" }, { label: "Lab", value: "lab" }, ]; export default function PinjamRuanganScreen() { const [tanggal, setTanggal] = useState(new Date()); const [mulai, setMulai] = useState(new Date()); const [selesai, setSelesai] = useState(new Date()); const [jenis, setJenis] = useState(null); const [kapasitas, setKapasitas] = useState(0); const [searched, setSearched] = useState(false); const [result, setResult] = useState([]); const formatDate = (date) => { return format(date, "yyyy-MM-dd"); }; const formatTime = (date) => { const hours = date.getHours().toString().padStart(2, "0"); const minutes = date.getMinutes().toString().padStart(2, "0"); const formattedTime = `${hours}:${minutes}`; return formattedTime; }; const changeDate = ({ type }, selectedDate) => { if (type === "set") { const currentDate = selectedDate; setTanggal(currentDate); } }; const changeMulai = ({ type }, selectedDate) => { if (type === "set") { const currentDate = selectedDate; setMulai(currentDate); } }; const changeSelesai = ({ type }, selectedDate) => { if (type === "set") { const currentDate = selectedDate; setSelesai(currentDate); } }; const handleSubmit = async () => { try { const response = await fetch( `http:(my-ip-address):4000/ruangan/cari-ruangan?jenis=${jenis}&tanggal=${formatDate( tanggal )}&mulai=${formatTime(mulai)}&selesai=${formatTime( selesai )}&kapasitas=${kapasitas}` ); const data = await response.json(); setResult(data.ruanganTersedia); setSearched(true); console.log(result.length); } catch (error) { console.log(error); } }; return ( <TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}> <SafeAreaView style={styles.container}> <Text style={styles.label}>Tanggal peminjaman: </Text> <DateTimePicker value={tanggal} mode="date" onChange={changeDate} style={styles.timePicker} /> <Text style={styles.label}>Dari jam: </Text> <DateTimePicker value={mulai} mode="time" onChange={changeMulai} style={styles.timePicker} /> <Text style={styles.label}>Sampai jam: </Text> <DateTimePicker value={selesai} mode="time" onChange={changeSelesai} style={styles.timePicker} /> <Dropdown style={styles.dropdown} maxHeight={300} itemContainerStyle={{ width: 600 }} data={data} labelField={"label"} valueField={"value"} placeholder="Pilih jenis ruangan" value={jenis} onChange={(value) => setJenis(value.value)} renderItem={(item) => { return ( <View style={styles.item}> <Text>{item.label}</Text> </View> ); }} /> <Text>Kapasitas:</Text> <TextInput style={styles.textInput} keyboardType="numeric" value={kapasitas} onChangeText={setKapasitas} /> <Button title="Cari ruangan" onPress={handleSubmit} /> {!searched ? ( <Text>Hasil pencarian ruangan akan ditampilkan disini</Text> ) : result.length === 0 ? ( <> <Text> Tidak ada ruangan yang sesuai dengan kriteria yang anda inginkan </Text> </> ) : ( <View> <FlatList data={result} renderItem={({ item }) => { return ( <View style={styles.card}> <Text style={styles.namaRuangan}>{item.nama}</Text> <Text style={styles.detailRuangan}>{item.jenis}</Text> <Text style={styles.detailRuangan}>{item.kapasitas}</Text> <Text style={styles.detailRuangan}>{item.lantai}</Text> </View> ); }} keyExtractor={(item) => item._id} ItemSeparatorComponent={<View style={{ height: 24 }} />} ListHeaderComponent={ <View style={{ marginTop: 20, marginBottom: 20 }}> <Text style={{ alignSelf: "center", fontSize: 30, fontWeight: "bold", }} > Ruangan yang tersedia </Text> </View> } /> </View> )} </SafeAreaView> </TouchableWithoutFeedback> ); } const styles = StyleSheet.create({ container: { padding: 24, justifyContent: "center", alignItems: "center", }, dropdown: { margin: 16, height: 50, alignSelf: "stretch", borderBottomColor: "gray", borderBottomWidth: 0.5, }, item: { padding: 17, flexDirection: "row", justifyContent: "space-between", alignItems: "center", }, label: { marginBottom: 10, }, timePicker: { marginBottom: 20, }, textInput: { borderWidth: 1, borderStyle: "solid", width: 50, }, card: { backgroundColor: "white", padding: 16, borderRadius: 8, borderWidth: 1, }, namaRuangan: { fontSize: 30, }, detailRuangan: { fontSize: 24, color: "#666666", }, }); </code>
import {
  StyleSheet,
  View,
  SafeAreaView,
  Text,
  TextInput,
  TouchableWithoutFeedback,
  Keyboard,
  Button,
  FlatList,
  ScrollView,
} from "react-native";
import { useEffect, useState } from "react";
import DateTimePicker from "@react-native-community/datetimepicker";
import { Dropdown } from "react-native-element-dropdown";
import { format } from "date-fns";

const data = [
  { label: "Selasar", value: "selasar" },
  { label: "Kelas", value: "kelas" },
  { label: "Lab", value: "lab" },
];

export default function PinjamRuanganScreen() {
  const [tanggal, setTanggal] = useState(new Date());
  const [mulai, setMulai] = useState(new Date());
  const [selesai, setSelesai] = useState(new Date());
  const [jenis, setJenis] = useState(null);
  const [kapasitas, setKapasitas] = useState(0);
  const [searched, setSearched] = useState(false);
  const [result, setResult] = useState([]);

  const formatDate = (date) => {
    return format(date, "yyyy-MM-dd");
  };

  const formatTime = (date) => {
    const hours = date.getHours().toString().padStart(2, "0");
    const minutes = date.getMinutes().toString().padStart(2, "0");
    const formattedTime = `${hours}:${minutes}`;
    return formattedTime;
  };

  const changeDate = ({ type }, selectedDate) => {    if (type === "set") {
      const currentDate = selectedDate;
      setTanggal(currentDate);
    }
  };

  const changeMulai = ({ type }, selectedDate) => {    if (type === "set") {
      const currentDate = selectedDate;
      setMulai(currentDate);
    }
  };

  const changeSelesai = ({ type }, selectedDate) => {    if (type === "set") {
      const currentDate = selectedDate;
      setSelesai(currentDate);
    }
  };

  const handleSubmit = async () => {
    try {
      const response = await fetch(
        `http:(my-ip-address):4000/ruangan/cari-ruangan?jenis=${jenis}&tanggal=${formatDate(
          tanggal
        )}&mulai=${formatTime(mulai)}&selesai=${formatTime(
          selesai
        )}&kapasitas=${kapasitas}`
      );
      const data = await response.json();
      setResult(data.ruanganTersedia);
      setSearched(true);
      console.log(result.length);
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
      <SafeAreaView style={styles.container}>
        <Text style={styles.label}>Tanggal peminjaman: </Text>
        <DateTimePicker
          value={tanggal}
          mode="date"
          onChange={changeDate}
          style={styles.timePicker}
        />
        <Text style={styles.label}>Dari jam: </Text>
        <DateTimePicker
          value={mulai}
          mode="time"
          onChange={changeMulai}
          style={styles.timePicker}
        />
        <Text style={styles.label}>Sampai jam: </Text>
        <DateTimePicker
          value={selesai}
          mode="time"
          onChange={changeSelesai}
          style={styles.timePicker}
        />
        <Dropdown
          style={styles.dropdown}
          maxHeight={300}
          itemContainerStyle={{ width: 600 }}
          data={data}
          labelField={"label"}
          valueField={"value"}
          placeholder="Pilih jenis ruangan"
          value={jenis}
          onChange={(value) => setJenis(value.value)}
          renderItem={(item) => {
            return (
              <View style={styles.item}>
                <Text>{item.label}</Text>
              </View>
            );
          }}
        />
        <Text>Kapasitas:</Text>

        <TextInput
          style={styles.textInput}
          keyboardType="numeric"
          value={kapasitas}
          onChangeText={setKapasitas}
        />
        <Button title="Cari ruangan" onPress={handleSubmit} />

        {!searched ? (
          <Text>Hasil pencarian ruangan akan ditampilkan disini</Text>
        ) : result.length === 0 ? (
          <>
            <Text>
              Tidak ada ruangan yang sesuai dengan kriteria yang anda inginkan
            </Text>
          </>
        ) : (
          <View>
            <FlatList
              data={result}
              renderItem={({ item }) => {
                return (
                  <View style={styles.card}>
                    <Text style={styles.namaRuangan}>{item.nama}</Text>
                    <Text style={styles.detailRuangan}>{item.jenis}</Text>
                    <Text style={styles.detailRuangan}>{item.kapasitas}</Text>
                    <Text style={styles.detailRuangan}>{item.lantai}</Text>
                  </View>
                );
              }}
              keyExtractor={(item) => item._id}
              ItemSeparatorComponent={<View style={{ height: 24 }} />}
              ListHeaderComponent={
                <View style={{ marginTop: 20, marginBottom: 20 }}>
                  <Text
                    style={{
                      alignSelf: "center",
                      fontSize: 30,
                      fontWeight: "bold",
                    }}
                  >
                    Ruangan yang tersedia
                  </Text>
                </View>
              }
            />
          </View>
        )}
      </SafeAreaView>
    </TouchableWithoutFeedback>
  );
}

const styles = StyleSheet.create({
  container: {
    padding: 24,
    justifyContent: "center",
    alignItems: "center",
  },
  dropdown: {
    margin: 16,
    height: 50,
    alignSelf: "stretch",
    borderBottomColor: "gray",
    borderBottomWidth: 0.5,
  },
  item: {
    padding: 17,
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center",
  },
  label: {
    marginBottom: 10,
  },
  timePicker: {
    marginBottom: 20,
  },
  textInput: {
    borderWidth: 1,
    borderStyle: "solid",
    width: 50,
  },
  card: {
    backgroundColor: "white",
    padding: 16,
    borderRadius: 8,
    borderWidth: 1,
  },
  namaRuangan: {
    fontSize: 30,
  },
  detailRuangan: {
    fontSize: 24,
    color: "#666666",
  },
});

And here’s the screenshot of the app (using expo go in ios):
Before submitting:

After submitting (In this state, the screen just stuck like this and i can’t scroll down to see the rest of the flat list, and i can’t even scroll up to see the upper part of the screen):

I expect the FlatList to be scrollable

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật