diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-07-31 18:11:19 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-07-31 18:31:13 +0200 |
| commit | d16bc5cc876e4d8b057525338ea5b01c3629f6c4 (patch) | |
| tree | b92b899df56af49eccf2384eff23bbe9975e262e /app/components/SelectLocation.js | |
| parent | aca43fd96c1d1937d2304d9602b84b24fe339b9b (diff) | |
| download | mullvadvpn-d16bc5cc876e4d8b057525338ea5b01c3629f6c4.tar.xz mullvadvpn-d16bc5cc876e4d8b057525338ea5b01c3629f6c4.zip | |
Auto scroll to selected location
Diffstat (limited to 'app/components/SelectLocation.js')
| -rw-r--r-- | app/components/SelectLocation.js | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/app/components/SelectLocation.js b/app/components/SelectLocation.js index 6257f89aef..afa765dba6 100644 --- a/app/components/SelectLocation.js +++ b/app/components/SelectLocation.js @@ -1,5 +1,6 @@ // @flow import * as React from 'react'; +import ReactDOM from 'react-dom'; import { View } from 'reactxp'; import { Layout, Container } from './Layout'; import CustomScrollbars from './CustomScrollbars'; @@ -59,8 +60,12 @@ export default class SelectLocation extends React.Component<SelectLocationProps, const scrollView = this._scrollView; if (scrollView && cell) { - //TODO: fix this when repairing the auto-scroll in customscrollbars. - //scrollView.scrollToElement(cell, 'middle'); + // eslint-disable-next-line react/no-find-dom-node + const cellDOMNode = ReactDOM.findDOMNode(cell); + + if (cellDOMNode instanceof HTMLElement) { + scrollView.scrollToElement(cellDOMNode, 'middle'); + } } } @@ -150,6 +155,12 @@ export default class SelectLocation extends React.Component<SelectLocationProps, _renderCountry(relayCountry: RelayLocationRedux) { const isSelected = this._isSelected({ country: relayCountry.code }); + const onRef = isSelected + ? (element) => { + this._selectedCell = element; + } + : undefined; + // either expanded by user or when the city selected within the country const isExpanded = this.state.expanded.includes(relayCountry.code); @@ -172,7 +183,8 @@ export default class SelectLocation extends React.Component<SelectLocationProps, style={isSelected ? styles.cell_selected : styles.cell} onPress={handleSelect} disabled={!relayCountry.hasActiveRelays} - testName="country"> + testName="country" + ref={onRef}> {this._relayStatusIndicator(relayCountry.hasActiveRelays, isSelected)} <Cell.Label>{relayCountry.name}</Cell.Label> |
