From 1c5562bb1cc0556c6084a190602a084d74d4e091 Mon Sep 17 00:00:00 2001 From: Definitely Not Vlad Date: Tue, 3 Mar 2020 16:35:45 +0100 Subject: [PATCH] Fix DropDownModal top padding and ListView renderHeader --- components/DropDownMenu/DropDownModal.js | 46 ++++++++++++++++++++---- components/ListView.js | 33 ++++++++--------- package.json | 2 +- 3 files changed, 55 insertions(+), 26 deletions(-) diff --git a/components/DropDownMenu/DropDownModal.js b/components/DropDownMenu/DropDownModal.js index 2daf97bd..19d44474 100644 --- a/components/DropDownMenu/DropDownModal.js +++ b/components/DropDownMenu/DropDownModal.js @@ -78,8 +78,10 @@ class DropDownModal extends PureComponent { this.close = this.close.bind(this); this.emitOnOptionSelectedEvent = this.emitOnOptionSelectedEvent.bind(this); + this.getKeyAreaHeights = this.getKeyAreaHeights.bind(this); this.renderGradient = this.renderGradient.bind(this); this.renderRow = this.renderRow.bind(this); + this.resolveModalStyle = this.resolveModalStyle.bind(this); this.selectOption = this.selectOption.bind(this); this.onOptionLayout = this.onOptionLayout.bind(this); @@ -149,6 +151,17 @@ class DropDownModal extends PureComponent { return { flex: 0, maxHeight: listViewHeight }; } + resolveModalStyle() { + const { style } = this.props; + + const { bufferHeight } = this.getKeyAreaHeights(); + + return { + ...style.modal, + paddingTop: style.modal.paddingTop + bufferHeight, + }; + } + calculateListViewHeight() { const { optionHeight } = this.state; const { options } = this.props; @@ -166,6 +179,24 @@ class DropDownModal extends PureComponent { ); } + getKeyAreaHeights() { + const { optionHeight } = this.state; + + const listViewHeight = this.calculateListViewHeight(); + const screenHeight = window.height; + const gradientHeight = optionHeight; + const transparencyHeight = listViewHeight - optionHeight * 2; + const bufferHeight = (screenHeight - listViewHeight) / 2; + + return { + listViewHeight, + screenHeight, + gradientHeight, + transparencyHeight, + bufferHeight, + }; + } + renderGradient() { const { style } = this.props; const { backgroundColor } = style.modal; @@ -182,11 +213,13 @@ class DropDownModal extends PureComponent { // following fashion // -> Buffer area -> Gradient area -> Transparency area -> Gradient Area -> Buffer Area - const listViewHeight = this.calculateListViewHeight(); - const screenHeight = window.height; - const gradientHeight = optionHeight; - const transparencyHeight = listViewHeight - optionHeight * 2; - const bufferHeight = (screenHeight - listViewHeight) / 2; + const { + listViewHeight, + screenHeight, + gradientHeight, + transparencyHeight, + bufferHeight, + } = this.getKeyAreaHeights(); const bufferColor = backgroundColor; const invertedColor = changeColorAlpha(backgroundColor, 0); @@ -249,6 +282,7 @@ class DropDownModal extends PureComponent { return null; } + const modalStyle = this.resolveModalStyle(); const listViewStyle = this.resolveListViewStyle(); const data = options.filter((option) => option[titleProperty]); @@ -260,7 +294,7 @@ class DropDownModal extends PureComponent { > - + {modalContentVisible && props.renderRow(data.item); + mappedProps.ListHeaderComponent = this.createListHeaderComponent(props.renderHeader, props.autoHideHeader); + mappedProps.renderItem = data => props.renderRow(data.item); mappedProps.ListFooterComponent = this.renderFooter; if (props.hasFeaturedItem && !props.sections) { mappedProps.sections = [ - { data: [props.data[0]], renderItem: (data) => props.renderFeaturedItem(data.item) }, + { data: [props.data[0]], renderItem: data => props.renderFeaturedItem(data.item) }, { data: props.data.slice(1) }, - ] + ]; } if (props.renderSectionHeader) { - mappedProps.renderSectionHeader = ({section}) => props.renderSectionHeader(section); - } - else if (!props.hasFeaturedItem) { - mappedProps.renderSectionHeader = ({section}) => this.renderDefaultSectionHeader(section); + mappedProps.renderSectionHeader = ({ section }) => props.renderSectionHeader(section); + } else if (!props.hasFeaturedItem) { + mappedProps.renderSectionHeader = ({ section }) => this.renderDefaultSectionHeader(section); } // events @@ -179,7 +174,7 @@ class ListView extends Component { this.scrollListView({ y: height, animated: false }); } - createRenderHeader(renderHeader, autoHideHeader) { + createListHeaderComponent(renderHeader, autoHideHeader) { if (!renderHeader) { return; } @@ -194,7 +189,7 @@ class ListView extends Component { } // eslint-disable-next-line consistent-return - return () => ( + return ( {renderHeader()} ); } diff --git a/package.json b/package.json index b186cb8e..f8547e15 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@shoutem/ui", - "version": "2.0.0", + "version": "2.0.2", "description": "Styleable set of components for React Native applications", "dependencies": { "@shoutem/animation": "~0.12.4",