Skip to content

Commit 1c5562b

Browse files
Fix DropDownModal top padding and ListView renderHeader
1 parent 8bb6806 commit 1c5562b

File tree

3 files changed

+55
-26
lines changed

3 files changed

+55
-26
lines changed

components/DropDownMenu/DropDownModal.js

+40-6
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ class DropDownModal extends PureComponent {
7878

7979
this.close = this.close.bind(this);
8080
this.emitOnOptionSelectedEvent = this.emitOnOptionSelectedEvent.bind(this);
81+
this.getKeyAreaHeights = this.getKeyAreaHeights.bind(this);
8182
this.renderGradient = this.renderGradient.bind(this);
8283
this.renderRow = this.renderRow.bind(this);
84+
this.resolveModalStyle = this.resolveModalStyle.bind(this);
8385
this.selectOption = this.selectOption.bind(this);
8486
this.onOptionLayout = this.onOptionLayout.bind(this);
8587

@@ -149,6 +151,17 @@ class DropDownModal extends PureComponent {
149151
return { flex: 0, maxHeight: listViewHeight };
150152
}
151153

154+
resolveModalStyle() {
155+
const { style } = this.props;
156+
157+
const { bufferHeight } = this.getKeyAreaHeights();
158+
159+
return {
160+
...style.modal,
161+
paddingTop: style.modal.paddingTop + bufferHeight,
162+
};
163+
}
164+
152165
calculateListViewHeight() {
153166
const { optionHeight } = this.state;
154167
const { options } = this.props;
@@ -166,6 +179,24 @@ class DropDownModal extends PureComponent {
166179
);
167180
}
168181

182+
getKeyAreaHeights() {
183+
const { optionHeight } = this.state;
184+
185+
const listViewHeight = this.calculateListViewHeight();
186+
const screenHeight = window.height;
187+
const gradientHeight = optionHeight;
188+
const transparencyHeight = listViewHeight - optionHeight * 2;
189+
const bufferHeight = (screenHeight - listViewHeight) / 2;
190+
191+
return {
192+
listViewHeight,
193+
screenHeight,
194+
gradientHeight,
195+
transparencyHeight,
196+
bufferHeight,
197+
};
198+
}
199+
169200
renderGradient() {
170201
const { style } = this.props;
171202
const { backgroundColor } = style.modal;
@@ -182,11 +213,13 @@ class DropDownModal extends PureComponent {
182213
// following fashion
183214
// -> Buffer area -> Gradient area -> Transparency area -> Gradient Area -> Buffer Area
184215

185-
const listViewHeight = this.calculateListViewHeight();
186-
const screenHeight = window.height;
187-
const gradientHeight = optionHeight;
188-
const transparencyHeight = listViewHeight - optionHeight * 2;
189-
const bufferHeight = (screenHeight - listViewHeight) / 2;
216+
const {
217+
listViewHeight,
218+
screenHeight,
219+
gradientHeight,
220+
transparencyHeight,
221+
bufferHeight,
222+
} = this.getKeyAreaHeights();
190223

191224
const bufferColor = backgroundColor;
192225
const invertedColor = changeColorAlpha(backgroundColor, 0);
@@ -249,6 +282,7 @@ class DropDownModal extends PureComponent {
249282
return null;
250283
}
251284

285+
const modalStyle = this.resolveModalStyle();
252286
const listViewStyle = this.resolveListViewStyle();
253287
const data = options.filter((option) => option[titleProperty]);
254288

@@ -260,7 +294,7 @@ class DropDownModal extends PureComponent {
260294
>
261295
<ZoomOut driver={this.timingDriver} maxFactor={1.1} style={{ flex: 1 }}>
262296
<FadeIn driver={this.timingDriver} style={{ flex: 1 }}>
263-
<View style={style.modal} styleName="vertical">
297+
<View style={modalStyle}>
264298
{modalContentVisible &&
265299
<ListView
266300
data={data}

components/ListView.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
RefreshControl,
88
StatusBar,
99
Platform,
10-
ScrollView,
1110
} from 'react-native';
1211
import _ from 'lodash';
1312

@@ -17,8 +16,6 @@ import { Caption } from './Text';
1716
import { Divider } from './Divider';
1817
import { Spinner } from './Spinner';
1918

20-
const scrollViewProps = _.keys(ScrollView.propTypes);
21-
2219
const Status = {
2320
LOADING: 'loading',
2421
LOADING_NEXT: 'loadingNext',
@@ -55,9 +52,8 @@ class ListView extends Component {
5552
}
5653

5754
return { status: Status.LOADING };
58-
} else {
59-
return { status: Status.IDLE };
6055
}
56+
return { status: Status.IDLE };
6157
}
6258

6359
constructor(props, context) {
@@ -76,9 +72,9 @@ class ListView extends Component {
7672
}
7773

7874
shouldComponentUpdate(nextProps, nextState) {
79-
return (nextProps.data !== this.props.data) ||
80-
(nextProps.loading !== this.props.loading) ||
81-
(nextState.status !== this.state.status);
75+
return (nextProps.data !== this.props.data)
76+
|| (nextProps.loading !== this.props.loading)
77+
|| (nextState.status !== this.state.status);
8278
}
8379

8480
componentWillUnmount() {
@@ -104,7 +100,7 @@ class ListView extends Component {
104100
* @returns {{}}
105101
*/
106102
getPropsToPass() {
107-
const props = this.props;
103+
const { props } = this;
108104
const mappedProps = {
109105
...props,
110106
};
@@ -118,22 +114,21 @@ class ListView extends Component {
118114
mappedProps.contentContainerStyle = props.style.listContent;
119115

120116
// rendering
121-
mappedProps.renderHeader = this.createRenderHeader(props.renderHeader, props.autoHideHeader);
122-
mappedProps.renderItem = (data) => props.renderRow(data.item);
117+
mappedProps.ListHeaderComponent = this.createListHeaderComponent(props.renderHeader, props.autoHideHeader);
118+
mappedProps.renderItem = data => props.renderRow(data.item);
123119
mappedProps.ListFooterComponent = this.renderFooter;
124120

125121
if (props.hasFeaturedItem && !props.sections) {
126122
mappedProps.sections = [
127-
{ data: [props.data[0]], renderItem: (data) => props.renderFeaturedItem(data.item) },
123+
{ data: [props.data[0]], renderItem: data => props.renderFeaturedItem(data.item) },
128124
{ data: props.data.slice(1) },
129-
]
125+
];
130126
}
131127

132128
if (props.renderSectionHeader) {
133-
mappedProps.renderSectionHeader = ({section}) => props.renderSectionHeader(section);
134-
}
135-
else if (!props.hasFeaturedItem) {
136-
mappedProps.renderSectionHeader = ({section}) => this.renderDefaultSectionHeader(section);
129+
mappedProps.renderSectionHeader = ({ section }) => props.renderSectionHeader(section);
130+
} else if (!props.hasFeaturedItem) {
131+
mappedProps.renderSectionHeader = ({ section }) => this.renderDefaultSectionHeader(section);
137132
}
138133

139134
// events
@@ -179,7 +174,7 @@ class ListView extends Component {
179174
this.scrollListView({ y: height, animated: false });
180175
}
181176

182-
createRenderHeader(renderHeader, autoHideHeader) {
177+
createListHeaderComponent(renderHeader, autoHideHeader) {
183178
if (!renderHeader) {
184179
return;
185180
}
@@ -194,7 +189,7 @@ class ListView extends Component {
194189
}
195190

196191
// eslint-disable-next-line consistent-return
197-
return () => (
192+
return (
198193
<View {...headerContainerProps}>{renderHeader()}</View>
199194
);
200195
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shoutem/ui",
3-
"version": "2.0.0",
3+
"version": "2.0.2",
44
"description": "Styleable set of components for React Native applications",
55
"dependencies": {
66
"@shoutem/animation": "~0.12.4",

0 commit comments

Comments
 (0)