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

Implement inverted prop. #25

Merged
merged 4 commits into from
Aug 2, 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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A RecyclerView implementation for ReactNative, that overcomes some limitations o
- **Control the scrolling velocity**: the `velocity` param in the `scrollToIndex` method is exactly for this
- **Initial scroll index**: specify the scroll position at startup, and there will be no flicker
- **Low memory usage**: it renders just the visible items plus some extra items around
- **Supports both scroll direction**: use the `inverted` prop to invert the scroll direction

## Caveats

Expand Down Expand Up @@ -93,7 +94,8 @@ Prop name | Description | Type | Default value
`initialListSize` | Number of items to render at startup. | int | 10
`initialScrollIndex` | Index of the item to scroll at startup | int | none
`initialScrollOffset` | Offset of the scroll position at startup | int | none
`itemAnimatorEnabled` | Whether animates items when they are added or removed | boolean | true
`inverted` | Reverses the scrolling direction; the first model from the data source is rendered at the bottom | boolean | false
`itemAnimatorEnabled` | Whether animates items when they are added or removed | bool | true
`ListHeaderComponent` | Component to render as header | component | none
`ListFooterComponent` | Component to render as footer | component | none
`ListEmptyComponent` | Component to render in case of no items | component | none
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd
this.getLayoutManager().startSmoothScroll(smoothScroller);
}

public void setInverted(boolean inverted) {
LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
layoutManager.setReverseLayout(inverted);
}

public void setItemAnimatorEnabled(boolean enabled) {
if (enabled) {
DefaultItemAnimator animator = new DefaultItemAnimator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public void setItemCount(RecyclerViewBackedScrollView parent, int itemCount) {
parent.getAdapter().notifyDataSetChanged();
}

@ReactProp(name = "inverted", defaultBoolean = false)
public void setInverted(RecyclerViewBackedScrollView parent, boolean inverted) {
parent.setInverted(inverted);
}

@ReactProp(name = "itemAnimatorEnabled", defaultBoolean = true)
public void setItemAnimatorEnabled(RecyclerViewBackedScrollView parent, boolean enabled) {
parent.setItemAnimatorEnabled(enabled);
Expand Down
2 changes: 2 additions & 0 deletions src/RecyclerViewList.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class RecyclerView extends React.PureComponent {
initialListSize: PropTypes.number,
initialScrollIndex: PropTypes.number,
initialScrollOffset: PropTypes.number,
inverted: PropTypes.bool,
itemAnimatorEnabled: PropTypes.bool,
ListHeaderComponent: PropTypes.element,
ListFooterComponent: PropTypes.element,
Expand All @@ -68,6 +69,7 @@ class RecyclerView extends React.PureComponent {
dataSource: new DataSource([], (item, i) => i),
initialListSize: 10,
windowSize: 30,
inverted: false,
itemAnimatorEnabled: true,
}

Expand Down