-
Notifications
You must be signed in to change notification settings - Fork 734
Feat/basic ui #1038
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
Merged
Merged
Feat/basic ui #1038
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b0f0275
Removed 'wheel` animation to match the design guidlines + added defau…
mendyEdri 668450b
added text configuration props
mendyEdri 30fbcf1
on selecting item - wheel will scroll to the right row
mendyEdri f65cb9f
added Fader and extract separators
mendyEdri fff8103
Calculate current active index
mendyEdri 97d09a0
added onChange event
mendyEdri c1d9e50
Increase visible rows to 5
mendyEdri 898ae71
change separator color to be visible
mendyEdri df0e136
added demo code
mendyEdri 2edabec
update reanimated version
mendyEdri f0a4bc7
types changes
mendyEdri b64ac06
type update
mendyEdri 7a5f95b
extract logic to it's own type
mendyEdri fc01367
refactor item center calculation to be based on the offset
mendyEdri 9ba7be1
update demo screen according to the new api
mendyEdri 1182829
pass style to item
mendyEdri d18486f
added unittests to listMiddleIndex calculations
mendyEdri d5ce1a7
made demo more clear
mendyEdri c13dcdf
Merge branch 'feat/WheelPicker' into feat/basic-ui
ethanshar 4bc951e
Update src/incubator/WheelPicker/index.tsx
mendyEdri cdb8c46
PR fixes - naming
mendyEdri ae33403
PR fixes - naming
mendyEdri f21f754
PR fix - optional chaining
mendyEdri 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 hidden or 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
This file contains hidden or 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
6 changes: 6 additions & 0 deletions
6
generatedTypes/incubator/WheelPicker/helpers/useListMiddleIndex.d.ts
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare type ItemType = { | ||
itemHeight: number; | ||
listSize: number; | ||
}; | ||
declare const _default: ({ itemHeight, listSize }: ItemType) => (offset: number) => number; | ||
export default _default; |
This file contains hidden or 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
This file contains hidden or 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
40 changes: 40 additions & 0 deletions
40
src/incubator/WheelPicker/__tests__/useListMiddleIndex.spec.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import useMiddleIndex from '../helpers/useListMiddleIndex'; | ||
|
||
describe('Finds list\'s middle index', () => { | ||
|
||
it('When list is at offset 0, it should return the index of the first item', () => { | ||
const sut = useMiddleIndex({itemHeight: 50, listSize: 10}); | ||
const offset = 0; | ||
expect(sut(offset)).toEqual(0); | ||
}); | ||
|
||
it('When list is at offset 100, it means we are at passed on 2 items', () => { | ||
const sut = useMiddleIndex({itemHeight: 50, listSize: 10}); | ||
const offset = 100; | ||
expect(sut(offset)).toEqual(2); | ||
}); | ||
|
||
it('Make sure calculation changes on the middle of the item height', () => { | ||
const sut = useMiddleIndex({itemHeight: 50, listSize: 10}); | ||
let offset = 24; | ||
expect(sut(offset)).toEqual(0); | ||
|
||
offset = 26; | ||
expect(sut(offset)).toEqual(1); | ||
}); | ||
|
||
it('Make sure calculation does not exceeds the number of items', () => { | ||
const sut = useMiddleIndex({itemHeight: 50, listSize: 10}); | ||
let offset = 501; | ||
expect(sut(offset)).toEqual(9); | ||
|
||
offset = 600; | ||
expect(sut(offset)).toEqual(9); | ||
}); | ||
|
||
it('Make sure calculation does not less then 0', () => { | ||
const sut = useMiddleIndex({itemHeight: 50, listSize: 10}); | ||
const offset = -100; | ||
expect(sut(offset)).toEqual(0); | ||
}); | ||
}); |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
type ItemType = { | ||
itemHeight: number; | ||
listSize: number; | ||
} | ||
|
||
export default ({itemHeight, listSize}: ItemType) => { | ||
const valueInRange = (value: number, min: number, max: number): number => { | ||
if (value < min || value === -0) { | ||
return min; | ||
} | ||
if (value > max) { | ||
return max; | ||
} | ||
return value; | ||
}; | ||
|
||
const middleIndex = (offset: number): number => { | ||
const calculatedIndex = Math.round(offset / itemHeight); | ||
return valueInRange(calculatedIndex, 0, listSize - 1); | ||
}; | ||
|
||
return middleIndex | ||
}; |
Oops, something went wrong.
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.
unselected sounds a little weird..
maybe use
activeColor
andinactiveColor
WDYT?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.
Agree!