react-native-swipeout icon indicating copy to clipboard operation
react-native-swipeout copied to clipboard

Cant center the icon of the swipe button

Open webdevsyd opened this issue 7 years ago • 8 comments

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

webdevsyd avatar Jan 02 '18 12:01 webdevsyd

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',

EyalSi avatar Jan 22 '18 18:01 EyalSi

try using alignSelf='center' in your CustomIcon

7laria avatar Mar 14 '18 16:03 7laria

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 </Text> </TouchableOpacity> ) } ],

        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}
            }
        ],`

rsp8055 avatar Mar 21 '18 10:03 rsp8055

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"),
  },
];

blackdynamo avatar Mar 21 '18 19:03 blackdynamo

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

grofis avatar Sep 05 '18 11:09 grofis

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> 

motogod avatar Oct 29 '18 04:10 motogod

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") } />

IsharaHansaka avatar Nov 10 '18 07:11 IsharaHansaka

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

huunghi20061997 avatar Dec 18 '18 09:12 huunghi20061997