-
Notifications
You must be signed in to change notification settings - Fork 427
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
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5195ef0
accomodating content insets and content container padding in visible …
rajatgupta26 c0117af
introduced contentInsets as a standard prop of RecyclerListView
rajatgupta26 2387c43
Using existing prop to deal with padding
naqvitalha b58aad9
Window scroll offset fix
naqvitalha 8bf7ce2
doc fix
naqvitalha 9dba4ab
Merge pull request #199 from Flipkart/insetAlternate
rajatgupta26 1ce5bd5
Merge branch 'master' into insetsFix
naqvitalha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,13 @@ import { Platform } from "react-native"; | |
const IS_WEB = !Platform || Platform.OS === "web"; | ||
//#endif | ||
|
||
export interface EdgeInsets { | ||
top: number; | ||
left: number; | ||
right: number; | ||
bottom: number; | ||
} | ||
|
||
/*** | ||
* To use on web, start importing from recyclerlistview/web. To make it even easier specify an alias in you builder of choice. | ||
*/ | ||
|
@@ -108,6 +115,12 @@ export interface RecyclerListViewProps { | |
//For all props that need to be proxied to inner/external scrollview. Put them in an object and they'll be spread | ||
//and passed down. For better typescript support. | ||
scrollViewProps?: object; | ||
|
||
/** | ||
* Use this prop to provide padding around list content instead of | ||
* using padding/margin in contentContainerStyle prop of scroll view. | ||
*/ | ||
contentInsets?: EdgeInsets; | ||
} | ||
export interface RecyclerListViewState { | ||
renderStack: RenderStack; | ||
|
@@ -148,6 +161,8 @@ export default class RecyclerListView extends React.Component<RecyclerListViewPr | |
|
||
private _defaultItemAnimator: ItemAnimator = new DefaultItemAnimator(); | ||
|
||
private _contentInsets: EdgeInsets = { top: 0, left: 0, bottom: 0, right: 0 }; | ||
|
||
constructor(props: RecyclerListViewProps) { | ||
super(props); | ||
this._onScroll = this._onScroll.bind(this); | ||
|
@@ -169,6 +184,7 @@ export default class RecyclerListView extends React.Component<RecyclerListViewPr | |
} | ||
|
||
public componentWillReceiveProps(newProps: RecyclerListViewProps): void { | ||
this._contentInsets = this.props.contentInsets ? this.props.contentInsets : { top: 0, left: 0, right: 0, bottom: 0 }; | ||
this._assertDependencyPresence(newProps); | ||
this._checkAndChangeLayouts(newProps); | ||
if (!this.props.onVisibleIndexesChanged) { | ||
|
@@ -319,6 +335,14 @@ export default class RecyclerListView extends React.Component<RecyclerListViewPr | |
ref={(scrollComponent) => this._scrollComponent = scrollComponent as BaseScrollComponent | null} | ||
{...this.props} | ||
{...this.props.scrollViewProps} | ||
{...{ | ||
contentContainerStyle: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's resolve conflicts if dev already sends this prop |
||
paddingTop: this._contentInsets.top, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All are |
||
paddingLeft: this._contentInsets.top, | ||
paddingBottom: this._contentInsets.top, | ||
paddingRight: this._contentInsets.top, | ||
}, | ||
}} | ||
onScroll={this._onScroll} | ||
onSizeChanged={this._onSizeChanged} | ||
contentHeight={this._initComplete ? this._virtualRenderer.getLayoutDimension().height : 0} | ||
|
@@ -512,7 +536,11 @@ export default class RecyclerListView extends React.Component<RecyclerListViewPr | |
} | ||
|
||
private _onScroll(offsetX: number, offsetY: number, rawEvent: ScrollEvent): void { | ||
this._virtualRenderer.updateOffset(offsetX, offsetY); | ||
const forwardOffsetX = offsetX - this._contentInsets.left; | ||
const forwardOffsetY = offsetX - this._contentInsets.top; | ||
|
||
this._virtualRenderer.updateOffset(forwardOffsetX, forwardOffsetY); | ||
|
||
if (this.props.onScroll) { | ||
this.props.onScroll(rawEvent, offsetX, offsetY); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this conflict with existing ScrollView prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just take paddingTop etc directly which we can override in give contentContainerStyle.
Also will need to be handled in web version