skip to Main Content

im using SwipeListView in my react native app , when i swipe left two buttons appear one for delete and the other for update , the problem i have here is the height of those Hidden item buttons are not like the size of rendreItem , i tried different ways to make it with same height but nothing works , i dont know what im missing
this is what i get
enter image description here

this this my code

const renderItem = (data) => (
    <View style={styles.cardContainer}>
      <View
        style={[
          styles.checkBoxContainer,
          data.item.done ? styles.checked : null,
        ]}
      />
      <TouchableOpacity>
        <View>
          <Text>{data.item.name}</Text>
        </View>
      </TouchableOpacity>
    </View>
  );

hiden Item

 const renderHiddenItem = (data, rowMap) => (
        <View style={styles.rowBack}>
          <TouchableOpacity
            style={[styles.actionButton, styles.updateButton]}
            onPress={() => updateItem(data.item)}
          >
            <Text style={styles.actionText}>Update</Text>
          </TouchableOpacity>
          <TouchableOpacity
            style={[styles.actionButton, styles.deleteButton]}
            onPress={() => deleteItem(data.item)}
          >
            <Text style={styles.actionText}>Delete</Text>
          </TouchableOpacity>
        </View>
      );

and this is how i render the items

<>
      <SwipeListView
        data={tasks}
        renderItem={renderItem}
        renderHiddenItem={renderHiddenItem}
        rightOpenValue={-150}
      />
    </>

and this is the style

cardContainer: {
    padding: 20,
    flexDirection: "row",
    backgroundColor: colors.normalTask,
    marginBottom: 10,
    borderRadius: 12,
    shadowColor: "#000",
    shadowOffset: {
      width: 0,
      height: 2,
    },
    shadowOpacity: 0.1,
    shadowRadius: 3,
    elevation: 3, // For Android
  },

  checkBoxContainer: {
    width: 20,
    height: 20,
    borderWidth: 1,
    marginRight: 10,
  },
  checked: {
  },
  rowBack: {
    alignItems: "center",
    flexDirection: "row-reverse", 
    padding: 20,
    height: "100%",
    },
  actionButton: {
    alignItems: "center",
    justifyContent: "center",
    width: 75,
    
    height: "100%",
    
  },
  updateButton: {
    backgroundColor: "blue",
  },
  deleteButton: {
    backgroundColor: "red",
  },
  actionText: {
    color: "#FFF",
  },

2

Answers


  1. Modify your actionButton style as:

    actionButton: {
        alignItems: "center",
        justifyContent: "center",
        width: 75,
        height: "80%",
        marginBottom: 10,
    },
    
    
    Login or Signup to reply.
  2. I tried on a blank page, if the others responses does not work for you, here is an updated style with a fixed height of 70

    cardContainer: {
        alignItems: 'center',
        paddingLeft: 20,
        flexDirection: 'row',
        backgroundColor: "purple",
        flex: 1,
        borderRadius: 12,
        shadowColor: '#000',
        shadowOffset: {
          width: 0,
          height: 2,
        },
        shadowOpacity: 0.1,
        shadowRadius: 3,
        elevation: 3, // For Android
        height: 70,
        },
    
      checkBoxContainer: {
        width: 20,
        height: 20,
        borderWidth: 1,
        marginRight: 10,
      },
      checked: {},
      rowBack: {
        alignItems: 'center',
        height: '100%',
        flexDirection: 'row-reverse',
      },
      actionButton: {
        alignItems: 'center',
        justifyContent: 'center',
        height: '100%',
        flex: 1,
      },
      updateButton: {
        backgroundColor: 'blue',
      },
      deleteButton: {
        backgroundColor: 'red',
      },
      actionText: {
        color: '#FFF',
      },
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search