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

feat: support max width parameter #141

Open
wants to merge 4 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
4 changes: 4 additions & 0 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface RecyclerListViewProps {
canChangeSize?: boolean;
distanceFromWindow?: number;
useWindowScroll?: boolean;
maxWidth?: number;
disableRecycling?: boolean;
forceNonDeterministicRendering?: boolean;
extendedState?: object;
Expand Down Expand Up @@ -541,6 +542,9 @@ RecyclerListView.propTypes = {
//Web only. Specify how far away the first list item is from window top. This is an adjustment for better optimization.
distanceFromWindow: PropTypes.number,

//Specify the max maxWidth of the list.
maxWidth: PropTypes.number,

//Web only. Layout elements in window instead of a scrollable div.
useWindowScroll: PropTypes.bool,

Expand Down
1 change: 1 addition & 0 deletions src/core/scrollcomponent/BaseScrollComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface ScrollComponentProps {
scrollThrottle?: number;
distanceFromWindow?: number;
useWindowScroll?: boolean;
maxWidth?: number;
}
export default abstract class BaseScrollComponent extends React.Component<ScrollComponentProps, {}> {
public abstract scrollTo(x: number, y: number, animate: boolean): void;
Expand Down
1 change: 1 addition & 0 deletions src/core/scrollcomponent/BaseScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ScrollViewDefaultProps {
style?: CSSProperties | null;
distanceFromWindow: number;
useWindowScroll: boolean;
maxWidth?: number;
}
export interface ScrollEvent {
nativeEvent: {
Expand Down
12 changes: 10 additions & 2 deletions src/platform/web/scrollcomponent/ScrollViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export default class ScrollViewer extends BaseScrollView {
if (this.props.onSizeChanged) {
if (this.props.useWindowScroll) {
this._startListeningToWindowEvents();
this.props.onSizeChanged({ height: window.innerHeight, width: window.innerWidth });
let maxWidth = window.innerWidth;
if ( this.props.maxWidth ) {
maxWidth = Math.min(window.innerWidth, this.props.maxWidth);
}
this.props.onSizeChanged({ height: window.innerHeight, width: maxWidth });
}
}
}
Expand Down Expand Up @@ -199,7 +203,11 @@ export default class ScrollViewer extends BaseScrollView {

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

Expand Down