Skip to content

Commit 4c7ec28

Browse files
committedNov 2, 2018
children lazy rendering, cleaning not implemented
1 parent b208226 commit 4c7ec28

File tree

4 files changed

+139
-139
lines changed

4 files changed

+139
-139
lines changed
 

‎.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module.exports = {
2121
"react/jsx-indent-props": ["error", 4],
2222
"no-nested-ternary": "off",
2323
"no-use-before-define": "off",
24-
"react/no-find-dom-node": "off"
24+
"react/no-find-dom-node": "off",
25+
"no-debugger": "off"
2526
},
2627
"plugins": ["react", "flowtype", "eslint-plugin-jest", "jest"]
2728
};

‎package.json

+108-108
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,112 @@
11
{
2-
"name": "react-tv-navigation-playground",
3-
"version": "0.1.0",
4-
"private": true,
5-
"dependencies": {
6-
"autoprefixer": "7.1.6",
7-
"babel-core": "6.26.0",
8-
"babel-eslint": "7.2.3",
9-
"babel-jest": "20.0.3",
10-
"babel-loader": "7.1.2",
11-
"babel-plugin-rewire": "^1.2.0",
12-
"babel-polyfill": "^6.26.0",
13-
"babel-preset-react-app": "^3.1.2",
14-
"babel-runtime": "6.26.0",
15-
"case-sensitive-paths-webpack-plugin": "2.1.1",
16-
"chalk": "1.1.3",
17-
"classnames": "^2.2.6",
18-
"css-loader": "0.28.7",
19-
"dotenv": "4.0.0",
20-
"dotenv-expand": "4.2.0",
21-
"eslint": "4.10.0",
22-
"eslint-config-react-app": "^2.1.0",
23-
"eslint-loader": "1.9.0",
24-
"eslint-plugin-flowtype": "2.39.1",
25-
"eslint-plugin-import": "2.8.0",
26-
"eslint-plugin-jsx-a11y": "5.1.1",
27-
"extract-text-webpack-plugin": "3.0.2",
28-
"file-loader": "1.1.5",
29-
"fs-extra": "3.0.1",
30-
"html-webpack-plugin": "2.29.0",
31-
"jest": "20.0.4",
32-
"lodash": "^4.17.10",
33-
"object-assign": "4.1.1",
34-
"postcss-flexbugs-fixes": "3.2.0",
35-
"postcss-loader": "2.0.8",
36-
"promise": "8.0.1",
37-
"prop-types": "^15.6.2",
38-
"raf": "3.4.0",
39-
"react": "^16.5.1",
40-
"react-dev-utils": "^5.0.2",
41-
"react-dom": "^16.4.1",
42-
"react-redux": "^5.0.7",
43-
"redux": "^4.0.0",
44-
"redux-logger": "^3.0.6",
45-
"resolve": "1.6.0",
46-
"style-loader": "0.19.0",
47-
"sw-precache-webpack-plugin": "0.11.4",
48-
"url-loader": "0.6.2",
49-
"webpack": "3.8.1",
50-
"webpack-dev-server": "2.11.3",
51-
"webpack-manifest-plugin": "1.3.2",
52-
"whatwg-fetch": "2.0.3"
53-
},
54-
"scripts": {
55-
"start": "PORT=9100 node scripts/start.js",
56-
"build": "node scripts/build.js",
57-
"test": "jest",
58-
"fix-eslint": "eslint src/** --fix"
59-
},
60-
"devDependencies": {
61-
"babel-eslint": "^8.1.1",
62-
"eslint": "^5.6.0",
63-
"eslint-config-airbnb-base": "^13.1.0",
64-
"eslint-plugin-flowtype": "^2.50.1",
65-
"eslint-plugin-import": "^2.14.0",
66-
"eslint-plugin-jest": "^21.26.2",
67-
"eslint-plugin-react": "^7.11.1",
68-
"flow-bin": "^0.81.0"
69-
},
70-
"jest": {
71-
"collectCoverageFrom": [
72-
"src/**/*.{js,jsx,mjs}"
73-
],
74-
"setupFiles": [
75-
"<rootDir>/config/polyfills.js"
76-
],
77-
"testMatch": [
78-
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
79-
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
80-
],
81-
"testEnvironment": "node",
82-
"testURL": "http://localhost",
83-
"transform": {
84-
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
85-
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
86-
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
2+
"name": "react-tv-navigation-playground",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"autoprefixer": "7.1.6",
7+
"babel-core": "6.26.0",
8+
"babel-eslint": "7.2.3",
9+
"babel-jest": "20.0.3",
10+
"babel-loader": "7.1.2",
11+
"babel-plugin-rewire": "^1.2.0",
12+
"babel-polyfill": "^6.26.0",
13+
"babel-preset-react-app": "^3.1.2",
14+
"babel-runtime": "6.26.0",
15+
"case-sensitive-paths-webpack-plugin": "2.1.1",
16+
"chalk": "1.1.3",
17+
"classnames": "^2.2.6",
18+
"css-loader": "0.28.7",
19+
"dotenv": "4.0.0",
20+
"dotenv-expand": "4.2.0",
21+
"eslint": "4.10.0",
22+
"eslint-config-react-app": "^2.1.0",
23+
"eslint-loader": "1.9.0",
24+
"eslint-plugin-flowtype": "2.39.1",
25+
"eslint-plugin-import": "2.8.0",
26+
"eslint-plugin-jsx-a11y": "5.1.1",
27+
"extract-text-webpack-plugin": "3.0.2",
28+
"file-loader": "1.1.5",
29+
"fs-extra": "3.0.1",
30+
"html-webpack-plugin": "2.29.0",
31+
"jest": "20.0.4",
32+
"lodash": "^4.17.10",
33+
"object-assign": "4.1.1",
34+
"postcss-flexbugs-fixes": "3.2.0",
35+
"postcss-loader": "2.0.8",
36+
"promise": "8.0.1",
37+
"prop-types": "^15.6.2",
38+
"raf": "3.4.0",
39+
"react": "^16.5.1",
40+
"react-dev-utils": "^5.0.2",
41+
"react-dom": "^16.4.1",
42+
"react-redux": "^5.0.7",
43+
"redux": "^4.0.0",
44+
"redux-logger": "^3.0.6",
45+
"resolve": "1.6.0",
46+
"style-loader": "0.19.0",
47+
"sw-precache-webpack-plugin": "0.11.4",
48+
"url-loader": "0.6.2",
49+
"webpack": "3.8.1",
50+
"webpack-dev-server": "2.11.3",
51+
"webpack-manifest-plugin": "1.3.2",
52+
"whatwg-fetch": "2.0.3"
8753
},
88-
"transformIgnorePatterns": [
89-
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
90-
],
91-
"moduleNameMapper": {
92-
"^react-native$": "react-native-web"
54+
"scripts": {
55+
"start": "PORT=9100 node scripts/start.js",
56+
"build": "node scripts/build.js",
57+
"test": "jest",
58+
"fix-eslint": "eslint src/** --fix"
9359
},
94-
"moduleFileExtensions": [
95-
"web.js",
96-
"js",
97-
"json",
98-
"web.jsx",
99-
"jsx",
100-
"node",
101-
"mjs"
102-
]
103-
},
104-
"babel": {
105-
"presets": [
106-
"react-app"
107-
]
108-
},
109-
"eslintConfig": {
110-
"extends": "react-app"
111-
}
60+
"devDependencies": {
61+
"babel-eslint": "^8.1.1",
62+
"eslint": "^5.6.0",
63+
"eslint-config-airbnb-base": "^13.1.0",
64+
"eslint-plugin-flowtype": "^2.50.1",
65+
"eslint-plugin-import": "^2.14.0",
66+
"eslint-plugin-jest": "^21.26.2",
67+
"eslint-plugin-react": "^7.11.1",
68+
"flow-bin": "^0.81.0"
69+
},
70+
"jest": {
71+
"collectCoverageFrom": [
72+
"src/**/*.{js,jsx,mjs}"
73+
],
74+
"setupFiles": [
75+
"<rootDir>/config/polyfills.js"
76+
],
77+
"testMatch": [
78+
"<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
79+
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
80+
],
81+
"testEnvironment": "node",
82+
"testURL": "http://localhost",
83+
"transform": {
84+
"^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
85+
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
86+
"^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
87+
},
88+
"transformIgnorePatterns": [
89+
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
90+
],
91+
"moduleNameMapper": {
92+
"^react-native$": "react-native-web"
93+
},
94+
"moduleFileExtensions": [
95+
"web.js",
96+
"js",
97+
"json",
98+
"web.jsx",
99+
"jsx",
100+
"node",
101+
"mjs"
102+
]
103+
},
104+
"babel": {
105+
"presets": [
106+
"react-app"
107+
]
108+
},
109+
"eslintConfig": {
110+
"extends": "react-app"
111+
}
112112
}

‎src/components/Layout/Columns/ColumnsComponent.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -518,18 +518,22 @@ export const getElementLeftRight = (
518518
export const recalculateChildrenStyles = (
519519
childrenRefs: Array<{ current: React.ElementRef }>,
520520
childrenStyles: Array<ChildStyle>,
521-
positionShift: number = 0,
522521
) => {
523-
const { updatedChildrenStyles: result } = childrenRefs.reduce(
524-
({ accumulatedWidth, updatedChildrenStyles }, { current: childRef }, index) => {
522+
const { updatedChildrenStyles: newChildrenStyles } = childrenRefs.reduce(
523+
(
524+
{ accumulatedWidth, updatedChildrenStyles },
525+
{ current: childRef },
526+
index,
527+
) => {
525528
// for right element calculate width and add it to the prev elemenent right
526529
// for left element put 0, calculate width, increase accumuldatedWidth
527530
const childStyles = childrenStyles[index];
528531
if (childStyles.shouldCalculatePositionAfterRender) {
532+
const prevChildRight = getPreviousChildRight(updatedChildrenStyles, index);
529533
const recalculatedChildStyles = getRecalculatedChildStyle(
530534
childRef,
531535
childStyles,
532-
positionShift,
536+
prevChildRight,
533537
);
534538
return {
535539
accumulatedWidth: recalculatedChildStyles.right,
@@ -549,19 +553,29 @@ export const recalculateChildrenStyles = (
549553
updatedChildrenStyles: [],
550554
},
551555
);
552-
return result;
556+
return newChildrenStyles;
553557
};
554558

559+
const getPreviousChildRight = (
560+
childrenStyles: ChildStyle[],
561+
currentIndex: number,
562+
) => (
563+
currentIndex > 0
564+
? childrenStyles[currentIndex - 1].right || 0
565+
: 0
566+
);
567+
555568
export const getRecalculatedChildStyle = (
556569
childRef: React.ElementRef<typeof FocusableComponent>,
557570
{ shouldPositionOutside, shouldCalculatePositionAfterRender, ...rest } : ChildStyle,
558-
shift: number,
571+
prevElementRight: number,
559572
) => {
560573
const { left, right } = getElementLeftRight(childRef);
574+
const width = right - left;
561575
return {
562576
...rest,
563-
left: left + shift,
564-
right: right + shift,
577+
left: prevElementRight,
578+
right: prevElementRight + width,
565579
};
566580
};
567581

‎src/components/Layout/LazyCollectionRenderer/index.js

+7-22
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ class LazyCollectionRenderer extends PureComponent {
5050
rangeStart,
5151
rangeEnd,
5252
});
53-
}, 1);
53+
}, 500);
5454
}
5555

5656
fetchDataForFocusedIndex = (newIndex) => {
5757
const {
5858
minVisibleAmountOnRight,
5959
minVisibleAmountOnLeft,
6060
totalAmount,
61-
shrinkRange,
6261
} = this.props;
6362

6463
const {
@@ -80,26 +79,12 @@ class LazyCollectionRenderer extends PureComponent {
8079
rangeStart: newRangeStart,
8180
rangeEnd: newRangeEnd,
8281
} = shouldRenderMoreOnLeft
83-
? shrinkRange(
84-
getIncreaseRangeOnLeft(rangeStart, rangeEnd, minVisibleAmountOnLeft),
85-
{
86-
leftBuffer: minVisibleAmountOnLeft,
87-
rightBuffer: minVisibleAmountOnRight,
88-
},
89-
-1,
90-
)
91-
: shrinkRange(
92-
getIncreaseRangeOnRight(
93-
rangeStart,
94-
rangeEnd,
95-
minVisibleAmountOnRight,
96-
totalAmount,
97-
),
98-
{
99-
leftBuffer: minVisibleAmountOnLeft,
100-
rightBuffer: minVisibleAmountOnRight,
101-
},
102-
1,
82+
? getIncreaseRangeOnLeft(rangeStart, rangeEnd, minVisibleAmountOnLeft)
83+
: getIncreaseRangeOnRight(
84+
rangeStart,
85+
rangeEnd,
86+
minVisibleAmountOnRight,
87+
totalAmount,
10388
);
10489

10590
const shouldRerenderElements = isRangeDifferent(

0 commit comments

Comments
 (0)
Please sign in to comment.