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

[RNMobile] Gallery - Button #18264

Merged
merged 3 commits into from
Nov 6, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions packages/block-library/src/gallery/gallery-button.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* External dependencies
*/
import { StyleSheet, TouchableOpacity, View } from 'react-native';
import { isString } from 'lodash';

/**
* WordPress dependencies
*/
import { Icon } from '@wordpress/components';

const styles = StyleSheet.create( {
buttonActive: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 6,
borderColor: '#2e4453',
backgroundColor: '#2e4453',
aspectRatio: 1,
},
} );

export function Button( props ) {
const {
icon,
onClick,
disabled,
'aria-disabled': ariaDisabled,
accessibilityLabel = 'button',
style,
} = props;

const buttonStyle = StyleSheet.compose( styles.buttonActive, style );

const isDisabled = disabled || ariaDisabled;

const fill = isDisabled ? 'gray' : 'white';

return (
<TouchableOpacity
activeOpacity={ 0.7 }
accessible={ true }
accessibilityLabel={ accessibilityLabel }
accessibilityRole={ 'button' }
onPress={ onClick }
disabled={ isDisabled }
>
<View style={ buttonStyle }>
{ isString( icon ) ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isString check is done inside Icon component, it shouldn't be necessary here, in theory...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're quite right about that 😄 thanks for pointing it out. I've removed the isString check.

<Icon icon={ icon } fill={ fill } size={ 24 } /> :
icon }
</View>
</TouchableOpacity>
);
}

export default Button;