Skip to content
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

WIP Detect browser for real max element size #936

Merged
merged 1 commit into from
Jan 13, 2018
Merged
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
4 changes: 2 additions & 2 deletions source/Grid/Grid.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SCROLL_DIRECTION_BACKWARD,
SCROLL_DIRECTION_FORWARD,
} from './defaultOverscanIndicesGetter';
import {DEFAULT_MAX_SCROLL_SIZE} from './utils/ScalingCellSizeAndPositionManager';
import {getMaxElementSize} from './utils/maxElementSize.js';

const DEFAULT_COLUMN_WIDTH = 50;
const DEFAULT_HEIGHT = 100;
Expand Down Expand Up @@ -2290,7 +2290,7 @@ describe('Grid', () => {
height: 100,
rowHeight: 100,
columnWidth: 100,
rowCount: DEFAULT_MAX_SCROLL_SIZE * 2 / 100, // lots of offset
rowCount: getMaxElementSize() * 2 / 100, // lots of offset
scrollTop: 2000,
}),
);
Expand Down
4 changes: 2 additions & 2 deletions source/Grid/utils/ScalingCellSizeAndPositionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type {Alignment, CellSizeGetter, VisibleCellRange} from '../types';

import CellSizeAndPositionManager from './CellSizeAndPositionManager';
import {getMaxElementSize} from './maxElementSize.js';

type ContainerSizeAndOffset = {
containerSize: number,
Expand All @@ -14,7 +15,6 @@ type ContainerSizeAndOffset = {
* After a certain position, the browser won't allow the user to scroll further (even via JavaScript scroll offset adjustments).
* This util picks a lower ceiling for max size and artificially adjusts positions within to make it transparent for users.
*/
export const DEFAULT_MAX_SCROLL_SIZE = 1500000;

type Params = {
maxScrollSize?: number,
Expand All @@ -31,7 +31,7 @@ export default class ScalingCellSizeAndPositionManager {
_cellSizeAndPositionManager: CellSizeAndPositionManager;
_maxScrollSize: number;

constructor({maxScrollSize = DEFAULT_MAX_SCROLL_SIZE, ...params}: Params) {
constructor({maxScrollSize = getMaxElementSize(), ...params}: Params) {
// Favor composition over inheritance to simplify IE10 support
this._cellSizeAndPositionManager = new CellSizeAndPositionManager(params);
this._maxScrollSize = maxScrollSize;
Expand Down
42 changes: 42 additions & 0 deletions source/Grid/utils/maxElementSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @flow

const DEFAULT_MAX_ELEMENT_SIZE = 1500000;

const isChrome = () => !!window.chrome && !!window.chrome.webstore;

const isFirefox = () => typeof window.InstallTrigger !== 'undefined';

const isSafari = () =>
/constructor/i.test(window.HTMLElement) ||
(p => p.toString() === '[object SafariRemoteNotification]')(
!window['safari'] ||
(typeof window.safari !== 'undefined' && window.safari.pushNotification),
);

const isOpera = () =>
(!!window.opr && !!window.opr.addons) ||
!!window.opera ||
navigator.userAgent.indexOf(' OPR/') >= 0;

const elementSizesPerBrowser = {
chrome: 33554428,
safari: 33554428,
opera: 33554428,
firefox: 17895696,
};

export const getMaxElementSize = (): number => {
if (isChrome()) {
return elementSizesPerBrowser.chrome;
}
if (isSafari()) {
return elementSizesPerBrowser.safari;
}
if (isOpera()) {
return elementSizesPerBrowser.opera;
}
if (isFirefox()) {
return elementSizesPerBrowser.firefox;
}
return DEFAULT_MAX_ELEMENT_SIZE;
};