Skip to content

Add option to use relative position instead of transform #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/index.es6
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ const examples = [
itemSizeGetter: getHeight,
type: 'variable'
},
{
length: 10000,
itemRenderer: renderVariableHeightItem,
itemSizeGetter: getHeight,
usePosition: true,
type: 'variable'
},
{
axis: 'x',
length: 10000,
Expand Down
38 changes: 29 additions & 9 deletions docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31102,7 +31102,8 @@ Cogs.define("react-list.js", function (COGS_REQUIRE, COGS_REQUIRE_ASYNC, module,
axis = _this$props7.axis,
length = _this$props7.length,
type = _this$props7.type,
useTranslate3d = _this$props7.useTranslate3d;
useTranslate3d = _this$props7.useTranslate3d,
usePosition = _this$props7.usePosition;
var _this$state6 = this.state,
from = _this$state6.from,
itemsPerRow = _this$state6.itemsPerRow;
Expand All @@ -31123,12 +31124,23 @@ Cogs.define("react-list.js", function (COGS_REQUIRE, COGS_REQUIRE_ASYNC, module,
var offset = this.getSpaceBefore(from, cache);
var x = axis === 'x' ? offset : 0;
var y = axis === 'y' ? offset : 0;
var transform = useTranslate3d ? "translate3d(".concat(x, "px, ").concat(y, "px, 0)") : "translate(".concat(x, "px, ").concat(y, "px)");
var listStyle = {
msTransform: transform,
WebkitTransform: transform,
transform: transform
};
var listStyle;

if (usePosition) {
listStyle = {
position: 'relative',
top: y,
left: x
};
} else {
var transform = useTranslate3d ? "translate3d(".concat(x, "px, ").concat(y, "px, 0)") : "translate(".concat(x, "px, ").concat(y, "px)");
listStyle = {
msTransform: transform,
WebkitTransform: transform,
transform: transform
};
}

return _react["default"].createElement("div", {
style: style,
ref: function ref(c) {
Expand Down Expand Up @@ -31156,7 +31168,8 @@ Cogs.define("react-list.js", function (COGS_REQUIRE, COGS_REQUIRE_ASYNC, module,
threshold: _propTypes["default"].number,
type: _propTypes["default"].oneOf(['simple', 'variable', 'uniform']),
useStaticSize: _propTypes["default"].bool,
useTranslate3d: _propTypes["default"].bool
useTranslate3d: _propTypes["default"].bool,
usePosition: _propTypes["default"].bool
}), _defineProperty(_class, "defaultProps", {
axis: 'y',
itemRenderer: function itemRenderer(index, key) {
Expand All @@ -31177,7 +31190,8 @@ Cogs.define("react-list.js", function (COGS_REQUIRE, COGS_REQUIRE_ASYNC, module,
threshold: 100,
type: 'simple',
useStaticSize: false,
useTranslate3d: false
useTranslate3d: false,
usePosition: false
}), _temp);
});
});
Expand Down Expand Up @@ -31317,6 +31331,12 @@ var examples = [{
itemRenderer: renderVariableHeightItem,
itemSizeGetter: getHeight,
type: 'variable'
}, {
length: 10000,
itemRenderer: renderVariableHeightItem,
itemSizeGetter: getHeight,
usePosition: true,
type: 'variable'
}, {
axis: 'x',
length: 10000,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "react-list",
"name": "@secoya/react-list",
"version": "0.8.14",
"author": "Casey Foster <c@sey.me>",
"license": "MIT",
Expand Down
33 changes: 22 additions & 11 deletions react-list.es6
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ module.exports = class ReactList extends Component {
threshold: PropTypes.number,
type: PropTypes.oneOf(['simple', 'variable', 'uniform']),
useStaticSize: PropTypes.bool,
useTranslate3d: PropTypes.bool
useTranslate3d: PropTypes.bool,
usePosition: PropTypes.bool
};

static defaultProps = {
Expand All @@ -119,7 +120,8 @@ module.exports = class ReactList extends Component {
threshold: 100,
type: 'simple',
useStaticSize: false,
useTranslate3d: false
useTranslate3d: false,
usePosition: false
};

static getDerivedStateFromProps(props, state) {
Expand Down Expand Up @@ -508,7 +510,7 @@ module.exports = class ReactList extends Component {
}

render() {
const { axis, length, type, useTranslate3d } = this.props;
const { axis, length, type, useTranslate3d, usePosition } = this.props;
const { from, itemsPerRow } = this.state;

const items = this.renderItems();
Expand All @@ -525,14 +527,23 @@ module.exports = class ReactList extends Component {
const offset = this.getSpaceBefore(from, cache);
const x = axis === 'x' ? offset : 0;
const y = axis === 'y' ? offset : 0;
const transform = useTranslate3d
? `translate3d(${x}px, ${y}px, 0)`
: `translate(${x}px, ${y}px)`;
const listStyle = {
msTransform: transform,
WebkitTransform: transform,
transform
};
let listStyle;
if (usePosition) {
listStyle = {
position: 'relative',
top: y,
left: x
};
} else {
const transform = useTranslate3d
? `translate3d(${x}px, ${y}px, 0)`
: `translate(${x}px, ${y}px)`;
listStyle = {
msTransform: transform,
WebkitTransform: transform,
transform
};
}
return (
<div style={style} ref={c => (this.el = c)}>
<div style={listStyle}>{items}</div>
Expand Down
32 changes: 23 additions & 9 deletions react-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,8 @@
axis = _this$props7.axis,
length = _this$props7.length,
type = _this$props7.type,
useTranslate3d = _this$props7.useTranslate3d;
useTranslate3d = _this$props7.useTranslate3d,
usePosition = _this$props7.usePosition;
var _this$state6 = this.state,
from = _this$state6.from,
itemsPerRow = _this$state6.itemsPerRow;
Expand All @@ -680,12 +681,23 @@
var offset = this.getSpaceBefore(from, cache);
var x = axis === 'x' ? offset : 0;
var y = axis === 'y' ? offset : 0;
var transform = useTranslate3d ? "translate3d(".concat(x, "px, ").concat(y, "px, 0)") : "translate(".concat(x, "px, ").concat(y, "px)");
var listStyle = {
msTransform: transform,
WebkitTransform: transform,
transform: transform
};
var listStyle;

if (usePosition) {
listStyle = {
position: 'relative',
top: y,
left: x
};
} else {
var transform = useTranslate3d ? "translate3d(".concat(x, "px, ").concat(y, "px, 0)") : "translate(".concat(x, "px, ").concat(y, "px)");
listStyle = {
msTransform: transform,
WebkitTransform: transform,
transform: transform
};
}

return _react["default"].createElement("div", {
style: style,
ref: function ref(c) {
Expand Down Expand Up @@ -713,7 +725,8 @@
threshold: _propTypes["default"].number,
type: _propTypes["default"].oneOf(['simple', 'variable', 'uniform']),
useStaticSize: _propTypes["default"].bool,
useTranslate3d: _propTypes["default"].bool
useTranslate3d: _propTypes["default"].bool,
usePosition: _propTypes["default"].bool
}), _defineProperty(_class, "defaultProps", {
axis: 'y',
itemRenderer: function itemRenderer(index, key) {
Expand All @@ -734,6 +747,7 @@
threshold: 100,
type: 'simple',
useStaticSize: false,
useTranslate3d: false
useTranslate3d: false,
usePosition: false
}), _temp);
});