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

accomodating content insets and content container padding in visible … #196

Merged
merged 7 commits into from
Jun 19, 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
14 changes: 12 additions & 2 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default class RecyclerListView extends React.Component<RecyclerListViewPr
initialRenderIndex: 0,
isHorizontal: false,
onEndReachedThreshold: 0,
distanceFromWindow: 0,
renderAheadOffset: IS_WEB ? 1000 : 250,
};

Expand Down Expand Up @@ -276,6 +277,10 @@ export default class RecyclerListView extends React.Component<RecyclerListViewPr

public scrollToOffset(x: number, y: number, animate: boolean = false): void {
if (this._scrollComponent) {
if (IS_WEB && this.props.useWindowScroll) {
x += this.props.distanceFromWindow!;
y += this.props.distanceFromWindow!;
}
if (this.props.isHorizontal) {
y = 0;
} else {
Expand Down Expand Up @@ -512,7 +517,9 @@ export default class RecyclerListView extends React.Component<RecyclerListViewPr
}

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

if (this.props.onScroll) {
this.props.onScroll(rawEvent, offsetX, offsetY);
}
Expand Down Expand Up @@ -594,7 +601,10 @@ RecyclerListView.propTypes = {
//Specify if size can change, listview will automatically relayout items. For web, works only with useWindowScroll = true
canChangeSize: PropTypes.bool,

//Web only. Specify how far away the first list item is from window top. This is an adjustment for better optimization.
//Specify how far away the first list item is from start of the RecyclerListView. e.g, if you have content padding on top or left.
//This is an adjustment for optimization and to make sure onVisibileIndexesChanged callback is correct.
//Ideally try to avoid setting large padding values on RLV content. If you have to please correct offsets reported, handle
//them in a custom ScrollView and pass it as an externalScrollView.
distanceFromWindow: PropTypes.number,

//Web only. Layout elements in window instead of a scrollable div.
Expand Down
1 change: 0 additions & 1 deletion src/core/scrollcomponent/BaseScrollComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export interface ScrollComponentProps {
isHorizontal?: boolean;
renderFooter?: () => JSX.Element | JSX.Element[] | null;
scrollThrottle?: number;
distanceFromWindow?: number;
useWindowScroll?: boolean;
onLayout?: any;
}
Expand Down
1 change: 0 additions & 1 deletion src/core/scrollcomponent/BaseScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface ScrollViewDefaultProps {
horizontal: boolean;
canChangeSize: boolean;
style?: CSSProperties | null;
distanceFromWindow: number;
useWindowScroll: boolean;
}
export interface ScrollEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default class ScrollComponent extends BaseScrollComponent {
// contentWidth,
// externalScrollView,
// canChangeSize,
// distanceFromWindow,
// renderFooter,
// isHorizontal,
// scrollThrottle,
Expand Down
6 changes: 3 additions & 3 deletions src/platform/web/scrollcomponent/ScrollEventNormalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ScrollEvent } from "../../../core/scrollcomponent/BaseScrollView";
export class ScrollEventNormalizer {
public divEvent: ScrollEvent;
public windowEvent: ScrollEvent;
constructor(target: HTMLDivElement, distanceFromWindow: number) {
constructor(target: HTMLDivElement) {
this.divEvent = {
nativeEvent: {
contentOffset: {
Expand Down Expand Up @@ -36,10 +36,10 @@ export class ScrollEventNormalizer {
nativeEvent: {
contentOffset: {
get x(): number {
return window.scrollX - distanceFromWindow;
return window.scrollX;
},
get y(): number {
return window.scrollY - distanceFromWindow;
return window.scrollY;
},
},
contentSize: {
Expand Down
15 changes: 3 additions & 12 deletions src/platform/web/scrollcomponent/ScrollViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const scrollEndEventSimulator = debounce((executable: () => void) => {
export default class ScrollViewer extends BaseScrollView {
public static defaultProps = {
canChangeSize: false,
distanceFromWindow: 0,
horizontal: false,
style: null,
useWindowScroll: false,
Expand Down Expand Up @@ -46,14 +45,6 @@ export default class ScrollViewer extends BaseScrollView {
}
}

public componentWillReceiveProps(nextProps: ScrollViewDefaultProps): void {
if (this.props.distanceFromWindow !== nextProps.distanceFromWindow) {
if (this._mainDivRef) {
this._scrollEventNormalizer = new ScrollEventNormalizer(this._mainDivRef, nextProps.distanceFromWindow);
}
}
}

public componentWillUnmount(): void {
window.removeEventListener("scroll", this._windowOnScroll);
if (this._mainDivRef) {
Expand Down Expand Up @@ -97,7 +88,7 @@ export default class ScrollViewer extends BaseScrollView {
private _setDivRef(div: HTMLDivElement | null): void {
this._mainDivRef = div;
if (div) {
this._scrollEventNormalizer = new ScrollEventNormalizer(div, this.props.distanceFromWindow);
this._scrollEventNormalizer = new ScrollEventNormalizer(div);
} else {
this._scrollEventNormalizer = null;
}
Expand Down Expand Up @@ -133,9 +124,9 @@ export default class ScrollViewer extends BaseScrollView {
}
} else {
if (this.props.horizontal) {
window.scrollTo(offset + this.props.distanceFromWindow, 0);
window.scrollTo(offset, 0);
} else {
window.scrollTo(0, offset + this.props.distanceFromWindow);
window.scrollTo(0, offset);
}
}
}
Expand Down