Skip to content

Add ability to send in height or width of the item #181

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

Open
wants to merge 1 commit 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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ npm i react-native-sortable-list --save

### API
#### Props
- **data** (Object) data source
- **data** (Object|Item[]) data source
- **order?** (Array) an array of keys from data, the order of keys from the array will be used to initial rows order
- **style?** (Object, Array)
- **contentContainerStyle?** (Object, Array) these styles will be applied to the inner scroll view content container
Expand Down Expand Up @@ -67,6 +67,11 @@ Called when the active row was released. Returns the key and the new list order.
`(key) => void`<br />
Called when a row was pressed.

#### Item
These are the optional values you can send in the single object of a data source that would modify the way `react-native-sortable-list` would interact with it.
- **height?** (Number) height of the item. overrides calculations
- **width?** (Number) width of the item. overrides calculations

#### Methods
- **scrollBy(dy?, animated?)** scrolls by a given y offset, either immediately or with a smooth animation
- **scrollTo(y?, animated?)** scrolls to a given y offset, either immediately or with a smooth animation
Expand Down
8 changes: 6 additions & 2 deletions src/SortableList.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,14 @@ export default class SortableList extends Component {
if (rowsLayouts) {
if (horizontal) {
location.x = nextX;
nextX += rowsLayouts[key] ? rowsLayouts[key].width : 0;

let width = item.width != null ? item.width : 0;
nextX += (width === 0 && rowsLayouts[key]) ? rowsLayouts[key].width : width;
} else {
location.y = nextY;
nextY += rowsLayouts[key] ? rowsLayouts[key].height : 0;

let height = item.height != null ? item.height : 0;
nextY += (height === 0 && rowsLayouts[key]) ? rowsLayouts[key].height : height;
}
}

Expand Down