Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to give gap between rows #95

Open
sinanverve7 opened this issue Oct 15, 2024 · 0 comments
Open

Not able to give gap between rows #95

sinanverve7 opened this issue Oct 15, 2024 · 0 comments

Comments

@sinanverve7
Copy link

i want my 4 boxes in a grid like model with a gap of 10.

i was partially able to give width between columns by adjusting boxes width.but giving gap between rows is not working anyway?

i tried to increase boxes hight and give some padding/margin at bottom but it's not working at all.
i tried to increase boxes height and give some white space bottom of the box but boxes are overlapping each other as shown in second screenshot.

simulator_screenshot_DF9E0481-EA62-4433-A719-5E0CF529945E

screen shot with increased box height

simulator_screenshot_06B235F0-00B8-4535-BBAE-9D14B48E2EA4

import { theme2 } from "@/src/app/theme2";
import { MyProfilePhoto } from "@/src/store/fe

atures/edit-profile/types";
import cnStyles from "@/src/styles";
import React, { useEffect, useState } from "react";
import { Dimensions, Image, StyleSheet, Text, View } from "react-native";
import { DraggableGrid } from "react-native-draggable-grid";
const width = Dimensions.get("window").width;

type PropType = {
  myphotos: MyProfilePhoto[];
  onChangeScrollEnable: (val: boolean) => void;
};

export default function PhotosBlock({
  myphotos,
  onChangeScrollEnable,
}: PropType) {
  const myPhotosLen = myphotos.length;
  const [datatest, setDataTest] = useState([] as DataSet[]);

  useEffect(() => {
    const newData = ["1", "2", "3", "4"].map((item, index) => {
      const disable = index >= myPhotosLen;
      return {
        key: item,
        uri: disable ? "" : myphotos[index].image,
        disabledDrag: disable,
        disabledReSorted: disable,
      };
    });
    setDataTest(newData);
  }, [myphotos]);

  const PendingText = (
    <View style={styles.pendingText}>
      <Text style={styles.underveifytext}>Under Verification</Text>
    </View>
  );
  const MainPhotoSymbol = (
    <View style={styles.mainText}>
      <Text>Main</Text>
    </View>
  );

  const renderItem = (item: DataSet, index: number) => {
    if (index >= myPhotosLen) {
      return (
        <View style={[styles.slotWrapper]}>
          <View style={[styles.imageSlot]}>
            <Text style={cnStyles.plusText}>+</Text>
          </View>
          <View style={styles.slotChild}>
            {/* <Text>mohammed sinan</Text> */}
          </View>
        </View>
      );
    }
    return (
      <View style={[styles.slotWrapper]}>
        {item.uri && (
          <Image
            source={{ uri: item.uri }}
            resizeMode="cover"
            style={[styles.imageSlot]}
          />
        )}
        <>
          {myphotos[index]?.photostatus == "0" && PendingText}
          {index === 0 && MainPhotoSymbol}
        </>
        <View style={styles.slotChild}></View>
      </View>
    );
  };

  return (
    <>
      <View
        style={{
          flexDirection: "row",
          flexWrap: "wrap",
          justifyContent: "space-between",
          width: "100%",
          marginBottom: 20,
          flex: 1,
        }}
      >
        <DraggableGrid
          key={datatest.length}
          style={{
            flex: 1,
            justifyContent: "space-between",
          }}
          onDragStart={() => {
            onChangeScrollEnable(false);
          }}
          numColumns={2}
          // itemHeight={300}
          renderItem={renderItem}
          data={datatest}
          onDragRelease={(data) => {
            onChangeScrollEnable(true);
            setDataTest(data); // need reset the props data sort after drag release
          }}
        />
      </View>
    </>
  );
}
const styles = StyleSheet.create({
  slotWrapper: {
    // width: width * 0.5,
    height: 250,
    alignItems: "center",
    justifyContent: "space-between",
  },
  slotChild: {
    // width: width * 0.5,
  },
  imageSlot: {
    width: width * 0.45,
    height: 185,
    backgroundColor: "#fff",
    borderRadius: 10,
    borderWidth: 1,
    borderColor: theme2.colors.borderColor,
    justifyContent: "center",
    alignItems: "center",

    // overflow: "hidden",
    // marginVertical: 10,
    // marginBottom: 44,
  },
  holdtext: {
    color: theme2.fonts.grayColor,
    textAlign: "center",
    width: "100%",
  },
  pendingText: {
    backgroundColor: theme2.colors.redcolor,
    position: "absolute",
    bottom: 0,
    width: "100%",
    padding: 5,
    borderBottomLeftRadius: 10,
    borderBottomRightRadius: 10,
  },
  underveifytext: { color: theme2.fonts.white, textAlign: "center" },
  mainText: {
    position: "absolute",
    left: 20,
    top: 44,
    borderWidth: 1,
    borderRadius: 10,
    paddingHorizontal: 6,
    paddingVertical: 2,
    backgroundColor: theme2.colors.primary,
  },

  //

  item: {
    width: 100,
    height: 100,
    borderRadius: 8,
    backgroundColor: "red",
    justifyContent: "center",
    alignItems: "center",
  },
  item_text: {
    fontSize: 40,
    color: "#FFFFFF",
  },
});

interface DataSet {
  key: string;
  uri: string;
  disabledDrag: boolean;
  disabledReSorted: boolean;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant