dancormier / react-native-swipeout

iOS-style swipeout buttons behind component
MIT License
2.62k stars 649 forks source link

Cant center the icon of the swipe button #249

Open webdevsyd opened 6 years ago

webdevsyd commented 6 years ago

I want to align the icon center horizontally, I manage to align it vertically using the textAlign: 'center' in the CustomIcon component but can't manage to center it horizontally. Tried several flexbox alignment but still no luck.

component: <View style={{
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
    alignSelf: 'center',
    alignContent: 'center'
  }}>
     <CustomIcon
         family={'MaterialCommunityIcons'}
         name={'calendar-remove'}
         style={{color: WHITE_COLOR, fontSize: 27, textAlign: 'center'}}
      />
</View>,

screen shot 2018-01-02 at 8 42 14 pm

EyalSi commented 6 years ago

on Android, I used textAlignVertical:'center', and textAlign:'center', for text component and it worked fine. For some reason it didn't work on iOS. Had to insert the text element in a view with: alignItems:'center', and justifyContent:'center',

7laria commented 6 years ago

try using alignSelf='center' in your CustomIcon

rsp8055 commented 6 years ago

By using the custom component it can easily be achieved by follows

` left: [ { component: ( <TouchableOpacity onPress={() => console.log("GOTO Profile")} style={{ flex: 1, backgroundColor: '#006633', justifyContent: 'center', alignItems: 'center' }}> <Image style={{ height: 20, width: 20 }} source={profile} /> <Text style={{ color: '#FFFFFF', fontSize: 12 }}> Profile ) } ],

        right: [
            {
                onPress: () => {

                    const deletingRow = this.state.activeRowKey;

                    Alert.alert(
                        'Delete',
                        'Are you sure you want to delete ?',
                        [
                            { text: 'No', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
                            {
                                text: 'Yes', onPress: () => {
                                    ChattingJson.splice(this.props.index, 1);
                                    this.props.parentFlatList.refreshFlatList(deletingRow);
                                }
                            },
                        ],
                        { cancelable: true }
                    );

                },
                text: 'Delete', type: 'delete', backgroundColor: 'purple', color: 'white', disabled: {false}
            }
        ],`
blackdynamo commented 6 years ago

I did something similar to solutions above:

export const ActionIcon = props => {
  const {color = "#FFFFFF", name, style = {}} = props;

  return (
    <View style={{flex: 1, alignItems: "center", justifyContent: "center"}}>
      <Icon style={{color, ...style}} ios={name} android={name} /> // This is a native base icon
    </View>
  );
};

Created a component which makes things a little cleaner and tidier. It can be used like this:

const actions = [
  {
    component: <ActionIcon name={"md-pricetag"} />,
    onPress: () => console.log("Do something"),
  },
];
grofis commented 6 years ago

set Swipeable‘s rightButtonContainerStyle={{alignItems:'center'}}

motogod commented 6 years ago

Base on @7laria suggestion, I try alignSelf: 'flex-start' fix the issue

example:

      <Swipeable
        rightButtons={[
          <TouchableOpacity style={[styles.rightSwipeItem, { backgroundColor: 'red' }]}>
            <Icon style={{ alignSelf: 'flex-start' }} name='home' />
          </TouchableOpacity>,
        ]}
      >
      <SomeViews />
     </Swipeable> 
IsharaHansaka commented 5 years ago

you can align vertical and horizontal by using Margins. <Image style={{ height: 35, width: 28, marginLeft: "auto", marginRight: "auto", marginTop: "auto", marginBottom: "auto" }} source={ require("../../../static/images/support-center/delete-icon-white.png") } />

huunghi20061997 commented 5 years ago

I try leftbutton marginleft is 32 in Icon and marginright in rightbutton is 32 . it is worked for me