scroll selected mon into view
This commit is contained in:
parent
e50ff2ce72
commit
db1b91c40f
44
dist/main-bundle.js
vendored
44
dist/main-bundle.js
vendored
@ -38659,27 +38659,28 @@ function (_react_1$default$Comp) {
|
|||||||
|
|
||||||
_this.handleChangeFilter = function (event) {
|
_this.handleChangeFilter = function (event) {
|
||||||
_this.props.handleChangeFilter(event.currentTarget.value).then(function () {
|
_this.props.handleChangeFilter(event.currentTarget.value).then(function () {
|
||||||
if (_this.listRef.current !== null) {
|
if (_this.state.listRef.current !== null) {
|
||||||
_this.listRef.current.resetAfterIndex(0, true);
|
_this.state.listRef.current.resetAfterIndex(0, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_this.handleClickClearFilter = function () {
|
_this.handleClickClearFilter = function () {
|
||||||
_this.props.handleChangeFilter('').then(function () {
|
_this.props.handleChangeFilter('').then(function () {
|
||||||
if (_this.listRef.current !== null) {
|
if (_this.state.listRef.current !== null) {
|
||||||
_this.listRef.current.resetAfterIndex(0, true);
|
_this.state.listRef.current.resetAfterIndex(0, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_this.state = {
|
_this.state = {
|
||||||
|
isListOpen: false,
|
||||||
|
listRef: react_1.default.createRef(),
|
||||||
dimensions: {
|
dimensions: {
|
||||||
width: -1,
|
width: -1,
|
||||||
height: -1
|
height: -1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_this.listRef = react_1.default.createRef();
|
|
||||||
_this.activatePokemonClickHandlers = new Map();
|
_this.activatePokemonClickHandlers = new Map();
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
@ -38733,7 +38734,7 @@ function (_react_1$default$Comp) {
|
|||||||
return react_1.default.createElement("div", {
|
return react_1.default.createElement("div", {
|
||||||
ref: measureRef
|
ref: measureRef
|
||||||
}, react_1.default.createElement(react_window_1.VariableSizeList, {
|
}, react_1.default.createElement(react_window_1.VariableSizeList, {
|
||||||
ref: _this2.listRef,
|
ref: _this2.state.listRef,
|
||||||
height: height,
|
height: height,
|
||||||
itemKey: _this2.getListItemKey,
|
itemKey: _this2.getListItemKey,
|
||||||
itemCount: listLength,
|
itemCount: listLength,
|
||||||
@ -38784,6 +38785,37 @@ function (_react_1$default$Comp) {
|
|||||||
className: formCss
|
className: formCss
|
||||||
}, formatter_1.formatForm(pokemon.form), " Form"));
|
}, formatter_1.formatForm(pokemon.form), " Form"));
|
||||||
}
|
}
|
||||||
|
}], [{
|
||||||
|
key: "getDerivedStateFromProps",
|
||||||
|
value: function getDerivedStateFromProps(nextProps, previousState) {
|
||||||
|
var wasOpen = previousState.isListOpen;
|
||||||
|
var isOpen = nextProps.isListOpen;
|
||||||
|
var listCurrent = previousState.listRef.current;
|
||||||
|
|
||||||
|
if (isOpen && !wasOpen) {
|
||||||
|
if (listCurrent !== null) {
|
||||||
|
var pokemonIndex = -1;
|
||||||
|
nextProps.pokemonList.some(function (pokemon, index) {
|
||||||
|
if (pokemon.id === nextProps.activePokemonId && pokemon.form === nextProps.activePokemonForm) {
|
||||||
|
pokemonIndex = index;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (pokemonIndex >= 0) {
|
||||||
|
setTimeout(function () {
|
||||||
|
return listCurrent.scrollToItem(pokemonIndex, 'center');
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isListOpen: isOpen && listCurrent !== null
|
||||||
|
};
|
||||||
|
}
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
return PokemonSelectList;
|
return PokemonSelectList;
|
||||||
|
|||||||
@ -27,6 +27,8 @@ export interface IPokemonSelectListProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
|
isListOpen : boolean;
|
||||||
|
listRef : React.RefObject<VariableSizeList>;
|
||||||
dimensions : {
|
dimensions : {
|
||||||
width : number;
|
width : number;
|
||||||
height : number;
|
height : number;
|
||||||
@ -39,20 +41,47 @@ interface IRowFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PokemonSelectList extends React.Component<IPokemonSelectListProps, IState> {
|
export class PokemonSelectList extends React.Component<IPokemonSelectListProps, IState> {
|
||||||
private listRef : React.RefObject<VariableSizeList>;
|
|
||||||
|
public static getDerivedStateFromProps(nextProps : IPokemonSelectListProps, previousState : IState) {
|
||||||
|
const wasOpen = previousState.isListOpen;
|
||||||
|
const isOpen = nextProps.isListOpen;
|
||||||
|
const listCurrent = previousState.listRef.current;
|
||||||
|
|
||||||
|
if (isOpen && !wasOpen) {
|
||||||
|
if (listCurrent !== null) {
|
||||||
|
let pokemonIndex : number = -1;
|
||||||
|
nextProps.pokemonList.some((pokemon, index) => {
|
||||||
|
if (pokemon.id === nextProps.activePokemonId && pokemon.form === nextProps.activePokemonForm) {
|
||||||
|
pokemonIndex = index;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (pokemonIndex >= 0) {
|
||||||
|
setTimeout(() => listCurrent.scrollToItem(pokemonIndex, 'center'), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isListOpen: isOpen && listCurrent !== null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private activatePokemonClickHandlers : Map<string, () => void>;
|
private activatePokemonClickHandlers : Map<string, () => void>;
|
||||||
|
|
||||||
constructor(props : IPokemonSelectListProps) {
|
constructor(props : IPokemonSelectListProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
isListOpen: false,
|
||||||
|
listRef: React.createRef(),
|
||||||
dimensions: {
|
dimensions: {
|
||||||
width: -1,
|
width: -1,
|
||||||
height: -1,
|
height: -1,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.listRef = React.createRef();
|
|
||||||
this.activatePokemonClickHandlers = new Map();
|
this.activatePokemonClickHandlers = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +146,7 @@ export class PokemonSelectList extends React.Component<IPokemonSelectListProps,
|
|||||||
({ measureRef }) => (
|
({ measureRef }) => (
|
||||||
<div ref={ measureRef }>
|
<div ref={ measureRef }>
|
||||||
<VariableSizeList
|
<VariableSizeList
|
||||||
ref={ this.listRef }
|
ref={ this.state.listRef }
|
||||||
height={ height }
|
height={ height }
|
||||||
itemKey={ this.getListItemKey }
|
itemKey={ this.getListItemKey }
|
||||||
itemCount={ listLength }
|
itemCount={ listLength }
|
||||||
@ -215,8 +244,8 @@ export class PokemonSelectList extends React.Component<IPokemonSelectListProps,
|
|||||||
private readonly handleChangeFilter = (event : React.ChangeEvent<HTMLInputElement>) => {
|
private readonly handleChangeFilter = (event : React.ChangeEvent<HTMLInputElement>) => {
|
||||||
this.props.handleChangeFilter(event.currentTarget.value)
|
this.props.handleChangeFilter(event.currentTarget.value)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (this.listRef.current !== null) {
|
if (this.state.listRef.current !== null) {
|
||||||
this.listRef.current.resetAfterIndex(0, true);
|
this.state.listRef.current.resetAfterIndex(0, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -224,8 +253,8 @@ export class PokemonSelectList extends React.Component<IPokemonSelectListProps,
|
|||||||
private readonly handleClickClearFilter = () => {
|
private readonly handleClickClearFilter = () => {
|
||||||
this.props.handleChangeFilter('')
|
this.props.handleChangeFilter('')
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (this.listRef.current !== null) {
|
if (this.state.listRef.current !== null) {
|
||||||
this.listRef.current.resetAfterIndex(0, true);
|
this.state.listRef.current.resetAfterIndex(0, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user