Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. interface IPictureWrapperProps {
  2. small: string;
  3. original: string;
  4. }
  5. class PictureWrapper extends React.PureComponent<IPictureWrapperProps> {
  6. public render() {
  7. const { small } = this.props;
  8. return <Picture isSmall imageUri={small} onPress={this.onPress} />;
  9. }
  10. private onPress = () => {
  11. // DO YOUR SHIT
  12. };
  13. }
  14.  
  15. interface IProps extends IThemeProps {
  16. isSmall?: boolean;
  17. imageUri: string;
  18. status?: string;
  19. buttonType?: EBUTTON_ACTION_ICONS;
  20. isTransparent?: boolean;
  21. }
  22.  
  23. interface IState {
  24. height: number;
  25. }
  26.  
  27. const BUTTON_CONTAINER_SIZE = 32;
  28.  
  29. export class PictureWithTheme extends Component<IProps, IState> {
  30. public static defaultProps = {
  31. isSmall: false,
  32. isTransparent: false,
  33. };
  34. public state: IState = { height: 0 };
  35.  
  36. public render() {
  37. const {
  38. buttonType,
  39. imageUri,
  40. isSmall,
  41. isTransparent,
  42. status,
  43. theme,
  44. } = this.props;
  45. return (
  46. <Container isSmall={!!isSmall}>
  47. <StyledImage
  48. uri={imageUri}
  49. resizeMode="cover"
  50. height={this.state.height}
  51. isTransparent={!!isTransparent}
  52. onLayout={this.onLayout}
  53. />
  54. </Container>
  55. );
  56. }
  57.  
  58. private onLayout = (event: LayoutChangeEvent) => {
  59. const { width } = event.nativeEvent.layout;
  60. this.setState({ height: width });
  61. };
  62. }
  63.  
  64. const Container = styled.View<{
  65. isSmall: boolean;
  66. }>`
  67. justify-content: center;
  68. width: ${({ isSmall }) => (isSmall ? 47 : 100)}%;
  69. margin-bottom: ${({ theme, isSmall }) =>
  70. isSmall ? theme.spacing.medium : 0};
  71. `;
  72.  
  73. const StyledImage = styled(Picture)<{
  74. height: number;
  75. isTransparent: boolean;
  76. }>`
  77. height: ${({ height }) => height}px;
  78. border-radius: 8px;
  79. opacity: ${({ isTransparent }) => (isTransparent ? 0.5 : 1)};
  80. `;
  81.  
  82. const Picture = withTheme(PictureWithTheme);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement