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

removed all binds #216

Merged
merged 5 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 7 additions & 14 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends

constructor(props: P) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please also add context as the second option param?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

super(props);
this._onScroll = this._onScroll.bind(this);
this._onSizeChanged = this._onSizeChanged.bind(this);
this._dataHasChanged = this._dataHasChanged.bind(this);
this.scrollToOffset = this.scrollToOffset.bind(this);
this._renderStackWhenReady = this._renderStackWhenReady.bind(this);
this._onViewContainerSizeChange = this._onViewContainerSizeChange.bind(this);

this._virtualRenderer = new VirtualRenderer(this._renderStackWhenReady, (offset) => {
this._pendingScrollToOffset = offset;
}, (index) => {
Expand Down Expand Up @@ -272,9 +265,9 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
this.scrollToIndex(lastIndex, animate);
}

public scrollToOffset(x: number, y: number, animate: boolean = false): void {
public scrollToOffset = (x: number, y: number, animate: boolean = false): void => {
if (this._scrollComponent) {
if (IS_WEB && this.props.useWindowScroll) {
if (this.props.useWindowScroll) {
x += this.props.distanceFromWindow!;
y += this.props.distanceFromWindow!;
}
Expand Down Expand Up @@ -400,7 +393,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
});
}

private _onSizeChanged(layout: Dimension): void {
private _onSizeChanged = (layout: Dimension): void => {
const hasHeightChanged = this._layout.height !== layout.height;
const hasWidthChanged = this._layout.width !== layout.width;
this._layout.height = layout.height;
Expand All @@ -423,7 +416,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
}
}

private _renderStackWhenReady(stack: RenderStack): void {
private _renderStackWhenReady = (stack: RenderStack): void => {
this.setState(() => {
return { renderStack: stack };
});
Expand Down Expand Up @@ -469,7 +462,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
}
}

private _dataHasChanged(row1: any, row2: any): boolean {
private _dataHasChanged = (row1: any, row2: any): boolean => {
return this.props.dataProvider.rowHasChanged(row1, row2);
}

Expand Down Expand Up @@ -508,7 +501,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
return null;
}

private _onViewContainerSizeChange(dim: Dimension, index: number): void {
private _onViewContainerSizeChange = (dim: Dimension, index: number): void => {
//Cannot be null here
(this._virtualRenderer.getLayoutManager() as LayoutManager).overrideLayout(index, dim);
if (this._relayoutReqIndex === -1) {
Expand Down Expand Up @@ -539,7 +532,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
return renderedItems;
}

private _onScroll(offsetX: number, offsetY: number, rawEvent: ScrollEvent): void {
private _onScroll = (offsetX: number, offsetY: number, rawEvent: ScrollEvent): void => {
//Adjusting offsets using distanceFromWindow
this._virtualRenderer.updateOffset(offsetX - this.props.distanceFromWindow!, offsetY - this.props.distanceFromWindow!);

Expand Down
4 changes: 1 addition & 3 deletions src/core/ViewabilityTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export default class ViewabilityTracker {
this.onEngagedRowsChanged = null;

this._relevantDim = { start: 0, end: 0 };

this._valueExtractorForBinarySearch = this._valueExtractorForBinarySearch.bind(this);
}

public init(): void {
Expand Down Expand Up @@ -175,7 +173,7 @@ export default class ViewabilityTracker {
return BinarySearch.findClosestHigherValueIndex(count, this._visibleWindow.start + bias, this._valueExtractorForBinarySearch);
}

private _valueExtractorForBinarySearch(index: number): number {
private _valueExtractorForBinarySearch = (index: number): number => {
const itemRect = this._layouts[index];
this._setRelevantBounds(itemRect, this._relevantDim);
return this._relevantDim.end;
Expand Down
6 changes: 2 additions & 4 deletions src/core/VirtualRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export default class VirtualRenderer {
this._startKey = 0;

this.onVisibleItemsChanged = null;
this._onEngagedItemsChanged = this._onEngagedItemsChanged.bind(this);
this._onVisibleItemsChanged = this._onVisibleItemsChanged.bind(this);
}

public getLayoutDimension(): Dimension {
Expand Down Expand Up @@ -339,13 +337,13 @@ export default class VirtualRenderer {
}
}

private _onVisibleItemsChanged(all: number[], now: number[], notNow: number[]): void {
private _onVisibleItemsChanged = (all: number[], now: number[], notNow: number[]): void => {
if (this.onVisibleItemsChanged) {
this.onVisibleItemsChanged(all, now, notNow);
}
}

private _onEngagedItemsChanged(all: number[], now: number[], notNow: number[]): void {
private _onEngagedItemsChanged = (all: number[], now: number[], notNow: number[]): void => {
const count = notNow.length;
let resolvedKey;
let disengagedIndex = 0;
Expand Down
8 changes: 2 additions & 6 deletions src/platform/reactnative/scrollcomponent/ScrollComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ export default class ScrollComponent extends BaseScrollComponent {

constructor(args: ScrollComponentProps) {
super(args);
this._onScroll = this._onScroll.bind(this);
this._onLayout = this._onLayout.bind(this);

this._height = 0;
this._width = 0;

this._isSizeChangedCalledOnce = false;
}

Expand Down Expand Up @@ -80,13 +76,13 @@ export default class ScrollComponent extends BaseScrollComponent {
);
}

private _onScroll(event?: NativeSyntheticEvent<NativeScrollEvent>): void {
private _onScroll = (event?: NativeSyntheticEvent<NativeScrollEvent>): void => {
if (event) {
this.props.onScroll(event.nativeEvent.contentOffset.x, event.nativeEvent.contentOffset.y, event);
}
}

private _onLayout(event: LayoutChangeEvent): void {
private _onLayout = (event: LayoutChangeEvent): void => {
if (this._height !== event.nativeEvent.layout.height || this._width !== event.nativeEvent.layout.width) {
this._height = event.nativeEvent.layout.height;
this._width = event.nativeEvent.layout.width;
Expand Down
11 changes: 2 additions & 9 deletions src/platform/reactnative/viewrenderer/ViewRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ import BaseViewRenderer, { ViewRendererProps } from "../../../core/viewrenderer/
export default class ViewRenderer extends BaseViewRenderer<any> {
private _dim: Dimension = { width: 0, height: 0 };
private _viewRef: React.Component<ViewProperties, React.ComponentState> | null = null;

constructor(props: ViewRendererProps<any>) {
super(props);
this._onLayout = this._onLayout.bind(this);
this._setRef = this._setRef.bind(this);
}

public render(): JSX.Element {
return this.props.forceNonDeterministicRendering ? (
<View ref={this._setRef}
Expand Down Expand Up @@ -53,11 +46,11 @@ export default class ViewRenderer extends BaseViewRenderer<any> {
return this._viewRef;
}

private _setRef(view: React.Component<ViewProperties, React.ComponentState> | null): void {
private _setRef = (view: React.Component<ViewProperties, React.ComponentState> | null): void => {
this._viewRef = view;
}

private _onLayout(event: LayoutChangeEvent): void {
private _onLayout = (event: LayoutChangeEvent): void => {
//Preventing layout thrashing in super fast scrolls where RN messes up onLayout event
const xDiff = Math.abs(this.props.x - event.nativeEvent.layout.x);
const yDiff = Math.abs(this.props.y - event.nativeEvent.layout.y);
Expand Down
7 changes: 2 additions & 5 deletions src/platform/web/scrollcomponent/ScrollComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ export default class ScrollComponent extends BaseScrollComponent {

constructor(args: ScrollComponentProps) {
super(args);
this._onScroll = this._onScroll.bind(this);
this._onSizeChanged = this._onSizeChanged.bind(this);

this._height = 0;
this._width = 0;
}
Expand Down Expand Up @@ -63,11 +60,11 @@ export default class ScrollComponent extends BaseScrollComponent {
);
}

private _onScroll(e: ScrollEvent): void {
private _onScroll = (e: ScrollEvent): void => {
this.props.onScroll(e.nativeEvent.contentOffset.x, e.nativeEvent.contentOffset.y, e);
}

private _onSizeChanged(event: Dimension): void {
private _onSizeChanged = (event: Dimension): void => {
if (this.props.onSizeChanged) {
this.props.onSizeChanged(event);
}
Expand Down
28 changes: 8 additions & 20 deletions src/platform/web/scrollcomponent/ScrollViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ export default class ScrollViewer extends BaseScrollView {
private _mainDivRef: HTMLDivElement | null = null;
private _isScrolling: boolean = false;
private _scrollEventNormalizer: ScrollEventNormalizer | null = null;
constructor(args: ScrollViewDefaultProps) {
super(args);
this._onScroll = this._onScroll.bind(this);
this._windowOnScroll = this._windowOnScroll.bind(this);
this._getRelevantOffset = this._getRelevantOffset.bind(this);
this._setRelevantOffset = this._setRelevantOffset.bind(this);
this._onWindowResize = this._onWindowResize.bind(this);
this._isScrollEnd = this._isScrollEnd.bind(this);
this._trackScrollOccurence = this._trackScrollOccurence.bind(this);
this._setDivRef = this._setDivRef.bind(this);
}

public componentDidMount(): void {
if (this.props.onSizeChanged) {
if (this.props.useWindowScroll) {
Expand Down Expand Up @@ -85,7 +73,7 @@ export default class ScrollViewer extends BaseScrollView {
</div>;
}

private _setDivRef(div: HTMLDivElement | null): void {
private _setDivRef = (div: HTMLDivElement | null): void => {
this._mainDivRef = div;
if (div) {
this._scrollEventNormalizer = new ScrollEventNormalizer(div);
Expand All @@ -94,7 +82,7 @@ export default class ScrollViewer extends BaseScrollView {
}
}

private _getRelevantOffset(): number {
private _getRelevantOffset = (): number => {
if (!this.props.useWindowScroll) {
if (this._mainDivRef) {
if (this.props.horizontal) {
Expand All @@ -113,7 +101,7 @@ export default class ScrollViewer extends BaseScrollView {
}
}

private _setRelevantOffset(offset: number): void {
private _setRelevantOffset = (offset: number): void => {
if (!this.props.useWindowScroll) {
if (this._mainDivRef) {
if (this.props.horizontal) {
Expand All @@ -131,14 +119,14 @@ export default class ScrollViewer extends BaseScrollView {
}
}

private _isScrollEnd(): void {
private _isScrollEnd = (): void => {
if (this._mainDivRef) {
this._mainDivRef.style.pointerEvents = "auto";
}
this._isScrolling = false;
}

private _trackScrollOccurence(): void {
private _trackScrollOccurence = (): void => {
if (!this._isScrolling) {
if (this._mainDivRef) {
this._mainDivRef.style.pointerEvents = "none";
Expand Down Expand Up @@ -182,21 +170,21 @@ export default class ScrollViewer extends BaseScrollView {
}
}

private _onWindowResize(): void {
private _onWindowResize = (): void => {
if (this.props.onSizeChanged && this.props.useWindowScroll) {
this.props.onSizeChanged({ height: window.innerHeight, width: window.innerWidth });
}
}

private _windowOnScroll(): void {
private _windowOnScroll = (): void => {
if (this.props.onScroll) {
if (this._scrollEventNormalizer) {
this.props.onScroll(this._scrollEventNormalizer.windowEvent);
}
}
}

private _onScroll(): void {
private _onScroll = (): void => {
if (this.props.onScroll) {
if (this._scrollEventNormalizer) {
this.props.onScroll(this._scrollEventNormalizer.divEvent);
Expand Down
8 changes: 1 addition & 7 deletions src/platform/web/viewrenderer/ViewRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ import BaseViewRenderer, { ViewRendererProps } from "../../../core/viewrenderer/
export default class ViewRenderer extends BaseViewRenderer<any> {
private _dim: Dimension = { width: 0, height: 0 };
private _mainDiv: HTMLDivElement | null = null;

constructor(props: ViewRendererProps<any>) {
super(props);
this._setRef = this._setRef.bind(this);
}

public componentDidMount(): void {
if (super.componentDidMount) {
super.componentDidMount();
Expand Down Expand Up @@ -58,7 +52,7 @@ export default class ViewRenderer extends BaseViewRenderer<any> {
protected getRef(): object | null {
return this._mainDiv;
}
private _setRef(div: HTMLDivElement | null): void {
private _setRef = (div: HTMLDivElement | null): void => {
this._mainDiv = div;
}
private _getTransform(): string {
Expand Down