react-native-drum-picker 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/LICENSE +21 -0
- package/README.md +252 -0
- package/android/build.gradle +68 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/drumpicker/DrumPickerAdapter.kt +108 -0
- package/android/src/main/java/com/drumpicker/DrumPickerChangeEvent.kt +25 -0
- package/android/src/main/java/com/drumpicker/DrumPickerDefaults.kt +19 -0
- package/android/src/main/java/com/drumpicker/DrumPickerPackage.kt +17 -0
- package/android/src/main/java/com/drumpicker/DrumPickerView.kt +583 -0
- package/android/src/main/java/com/drumpicker/DrumPickerViewManager.kt +108 -0
- package/lib/module/DateDrumPicker.js +153 -0
- package/lib/module/DrumPicker.js +6 -0
- package/lib/module/DrumPicker.native.js +63 -0
- package/lib/module/DrumPickerViewNativeComponent.ts +31 -0
- package/lib/module/dateDrumPickerLogic.js +82 -0
- package/lib/module/index.js +5 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +4 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/DateDrumPicker.d.ts +32 -0
- package/lib/typescript/src/DrumPicker.d.ts +3 -0
- package/lib/typescript/src/DrumPicker.native.d.ts +3 -0
- package/lib/typescript/src/DrumPickerViewNativeComponent.d.ts +25 -0
- package/lib/typescript/src/dateDrumPickerLogic.d.ts +20 -0
- package/lib/typescript/src/index.d.ts +5 -0
- package/lib/typescript/src/types.d.ts +24 -0
- package/package.json +189 -0
- package/react-native.config.js +13 -0
- package/src/DateDrumPicker.tsx +267 -0
- package/src/DrumPicker.native.tsx +68 -0
- package/src/DrumPicker.tsx +7 -0
- package/src/DrumPickerViewNativeComponent.ts +31 -0
- package/src/dateDrumPickerLogic.ts +95 -0
- package/src/index.tsx +15 -0
- package/src/types.ts +25 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Android-native `DrumPicker` Fabric view (Kotlin, `RecyclerView`, snap-to-center).
|
|
13
|
+
- TypeScript public API and codegen spec (`DrumPickerView`).
|
|
14
|
+
- `DateDrumPicker` wrapper with flexible modes (`day`, `month`, `year`, combinations).
|
|
15
|
+
- Transparent background support (`backgroundColor`, `containerBackgroundColor`, `itemBackgroundColor`).
|
|
16
|
+
- iOS-style center selection indicator (optional).
|
|
17
|
+
- Distance-based text fade and size interpolation while scrolling.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- (nothing yet)
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- (nothing yet)
|
|
26
|
+
|
|
27
|
+
## [0.1.0] - TBD
|
|
28
|
+
|
|
29
|
+
> First public npm release when published. Replace **TBD** with the release date.
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- Initial open-source release (Android only).
|
|
34
|
+
|
|
35
|
+
[Unreleased]: https://github.com/scrollDynasty/react-native-drum-picker/compare/v0.1.0...HEAD
|
|
36
|
+
[0.1.0]: https://github.com/scrollDynasty/react-native-drum-picker/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Umar Matyokubov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# react-native-drum-picker
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/react-native-drum-picker)
|
|
4
|
+
[](https://github.com/scrollDynasty/react-native-drum-picker/blob/main/LICENSE)
|
|
5
|
+
[](https://reactnative.dev)
|
|
6
|
+
[](https://reactnative.dev)
|
|
7
|
+
|
|
8
|
+
A smooth **Android-native** iOS-style drum/wheel picker for React Native (Fabric / New Architecture).
|
|
9
|
+
|
|
10
|
+
## Preview
|
|
11
|
+
|
|
12
|
+
> Add a GIF or screenshot here.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- Android-native implementation (Kotlin + `RecyclerView`)
|
|
17
|
+
- iOS-style wheel / drum picker with smooth snapping
|
|
18
|
+
- Center selection indicator (optional)
|
|
19
|
+
- Transparent background by default
|
|
20
|
+
- Custom text colors and sizes
|
|
21
|
+
- TypeScript API
|
|
22
|
+
- Flexible `DateDrumPicker` wrapper (day / month / year columns)
|
|
23
|
+
- Fabric View / New Architecture
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
yarn add react-native-drum-picker
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm install react-native-drum-picker
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This package includes **native Android code**. Rebuild your app after installing:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
cd android && ./gradlew clean && cd ..
|
|
39
|
+
npx react-native run-android
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
On Windows:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
cd android
|
|
46
|
+
.\gradlew clean
|
|
47
|
+
cd ..
|
|
48
|
+
npx react-native run-android
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Platform support
|
|
52
|
+
|
|
53
|
+
| Platform | Status |
|
|
54
|
+
|----------|--------|
|
|
55
|
+
| Android | Supported |
|
|
56
|
+
| iOS | Not supported yet |
|
|
57
|
+
| Web | Not supported |
|
|
58
|
+
|
|
59
|
+
Requires **React Native 0.76+** with the **New Architecture** enabled.
|
|
60
|
+
|
|
61
|
+
## Basic usage
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { DrumPicker } from 'react-native-drum-picker';
|
|
65
|
+
|
|
66
|
+
export function Example() {
|
|
67
|
+
return (
|
|
68
|
+
<DrumPicker
|
|
69
|
+
items={['Mon 7 Sep', 'Tue 8 Sep', 'Wed 9 Sep']}
|
|
70
|
+
selectedIndex={1}
|
|
71
|
+
itemHeight={44}
|
|
72
|
+
visibleItemCount={5}
|
|
73
|
+
onChange={(event) => {
|
|
74
|
+
console.log(event.nativeEvent.index, event.nativeEvent.value);
|
|
75
|
+
}}
|
|
76
|
+
style={{ width: 150, height: 220 }}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Set `style.height` ≈ `itemHeight * visibleItemCount` (default `44 × 5 = 220`).
|
|
83
|
+
|
|
84
|
+
## DateDrumPicker
|
|
85
|
+
|
|
86
|
+
Higher-level date columns (TypeScript only). Renders **wheels only** — no built-in titles; add labels in your app if needed.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { useState } from 'react';
|
|
90
|
+
import { DateDrumPicker } from 'react-native-drum-picker';
|
|
91
|
+
|
|
92
|
+
export function DateExample() {
|
|
93
|
+
const [date, setDate] = useState({ day: 21, month: 5, year: 2026 });
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<DateDrumPicker
|
|
97
|
+
mode="day-month-year"
|
|
98
|
+
value={date}
|
|
99
|
+
onChange={setDate}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
<DateDrumPicker
|
|
107
|
+
mode="month-year"
|
|
108
|
+
monthFormat="long"
|
|
109
|
+
minYear={2020}
|
|
110
|
+
maxYear={2035}
|
|
111
|
+
value={{ month: 5, year: 2026 }}
|
|
112
|
+
onChange={(value) => console.log(value)}
|
|
113
|
+
/>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Controlled:** pass `value` and update in `onChange`.
|
|
117
|
+
**Uncontrolled:** omit `value`; internal state updates and `onChange` still fires.
|
|
118
|
+
|
|
119
|
+
Day count follows month/year (e.g. February has 28/29 days).
|
|
120
|
+
|
|
121
|
+
## API reference
|
|
122
|
+
|
|
123
|
+
### `DrumPicker`
|
|
124
|
+
|
|
125
|
+
| Prop | Type | Default | Description |
|
|
126
|
+
|------|------|---------|-------------|
|
|
127
|
+
| `items` | `string[]` | required | Wheel labels |
|
|
128
|
+
| `selectedIndex` | `number` | `0` | Selected row index |
|
|
129
|
+
| `itemHeight` | `number` | `44` | Row height (dp) |
|
|
130
|
+
| `visibleItemCount` | `number` | `5` | Visible rows (odd recommended) |
|
|
131
|
+
| `textColor` | `string` | `#8E8E93` | Unselected text |
|
|
132
|
+
| `selectedTextColor` | `string` | `#1C1C1E` | Selected text |
|
|
133
|
+
| `textSize` | `number` | `20` | Unselected size (sp) |
|
|
134
|
+
| `selectedTextSize` | `number` | `22` | Selected size (sp) |
|
|
135
|
+
| `backgroundColor` | `string` | `transparent` | Root view background |
|
|
136
|
+
| `containerBackgroundColor` | `string` | `transparent` | `RecyclerView` background |
|
|
137
|
+
| `itemBackgroundColor` | `string` | `transparent` | Row background |
|
|
138
|
+
| `showSelectionIndicator` | `boolean` | `true` | Center lines |
|
|
139
|
+
| `selectionIndicatorColor` | `string` | `#D1D1D6` | Line color |
|
|
140
|
+
| `selectionIndicatorHeight` | `number` | `1` | Line thickness (dp) |
|
|
141
|
+
| `onChange` | `function` | — | `nativeEvent: { index, value }` |
|
|
142
|
+
| `style` | `ViewStyle` | — | Size and layout |
|
|
143
|
+
|
|
144
|
+
### `DateDrumPicker`
|
|
145
|
+
|
|
146
|
+
| Prop | Type | Default | Description |
|
|
147
|
+
|------|------|---------|-------------|
|
|
148
|
+
| `mode` | `DateDrumPickerMode` | `day-month-year` | Which columns to show |
|
|
149
|
+
| `value` | `{ day?, month?, year? }` | — | Controlled value |
|
|
150
|
+
| `onChange` | `function` | — | `{ day, month, year }` |
|
|
151
|
+
| `minYear` | `number` | now − 100 | Year range start |
|
|
152
|
+
| `maxYear` | `number` | now + 50 | Year range end |
|
|
153
|
+
| `monthFormat` | `'short' \| 'long' \| 'number'` | `short` | Month labels |
|
|
154
|
+
| `locale` | `string` | `en` | `Intl` locale for month names |
|
|
155
|
+
| `itemHeight` | `number` | `44` | Passed to each column |
|
|
156
|
+
| `visibleItemCount` | `number` | `5` | Passed to each column |
|
|
157
|
+
| `textColor` | `string` | — | Passed to each column |
|
|
158
|
+
| `selectedTextColor` | `string` | — | Passed to each column |
|
|
159
|
+
| `textSize` | `number` | — | Passed to each column |
|
|
160
|
+
| `selectedTextSize` | `number` | — | Passed to each column |
|
|
161
|
+
| `showSelectionIndicator` | `boolean` | — | Passed to each column |
|
|
162
|
+
| `selectionIndicatorColor` | `string` | — | Passed to each column |
|
|
163
|
+
| `selectionIndicatorHeight` | `number` | — | Passed to each column |
|
|
164
|
+
| `backgroundColor` | `string` | `transparent` | Passed to each column |
|
|
165
|
+
| `itemBackgroundColor` | `string` | `transparent` | Passed to each column |
|
|
166
|
+
| `containerBackgroundColor` | `string` | `transparent` | Passed to each column |
|
|
167
|
+
| `style` | `ViewStyle` | — | Row container |
|
|
168
|
+
| `columnStyle` | `ViewStyle` | — | All columns |
|
|
169
|
+
| `columnStyles` | `object` | — | Per column: `day`, `month`, `year` |
|
|
170
|
+
|
|
171
|
+
### `DateDrumPicker` modes
|
|
172
|
+
|
|
173
|
+
Column order is left → right:
|
|
174
|
+
|
|
175
|
+
| `mode` | Columns |
|
|
176
|
+
|--------|---------|
|
|
177
|
+
| `day` | day |
|
|
178
|
+
| `month` | month |
|
|
179
|
+
| `year` | year |
|
|
180
|
+
| `day-month` | day, month |
|
|
181
|
+
| `month-year` | month, year |
|
|
182
|
+
| `day-month-year` | day, month, year |
|
|
183
|
+
| `month-day-year` | month, day, year |
|
|
184
|
+
| `year-month-day` | year, month, day |
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
type DateDrumPickerMode =
|
|
188
|
+
| 'day'
|
|
189
|
+
| 'month'
|
|
190
|
+
| 'year'
|
|
191
|
+
| 'day-month'
|
|
192
|
+
| 'month-year'
|
|
193
|
+
| 'day-month-year'
|
|
194
|
+
| 'month-day-year'
|
|
195
|
+
| 'year-month-day';
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Styling
|
|
199
|
+
|
|
200
|
+
Backgrounds are **transparent by default**. Only text and optional indicator lines are visible.
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
<DrumPicker
|
|
204
|
+
items={['Small', 'Medium', 'Large']}
|
|
205
|
+
selectedTextColor="#111827"
|
|
206
|
+
textColor="#9CA3AF"
|
|
207
|
+
selectionIndicatorColor="#D1D1D6"
|
|
208
|
+
backgroundColor="transparent"
|
|
209
|
+
style={{ width: 120, height: 220 }}
|
|
210
|
+
/>
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Use an **odd** `visibleItemCount` (e.g. `5`) for a symmetric wheel.
|
|
214
|
+
|
|
215
|
+
## Troubleshooting
|
|
216
|
+
|
|
217
|
+
| Issue | What to try |
|
|
218
|
+
|-------|-------------|
|
|
219
|
+
| Must rebuild after install | Native library — run a full Android rebuild |
|
|
220
|
+
| Metro shows old code | `npx react-native start --reset-cache` |
|
|
221
|
+
| Gradle / build errors | `cd android && ./gradlew clean` (Windows: `.\gradlew clean`) |
|
|
222
|
+
| `adb` not found | Install Android SDK Platform-Tools; add to `PATH` |
|
|
223
|
+
| Empty or white picker | Enable New Architecture; set explicit `width` / `height` in `style` |
|
|
224
|
+
| Props not applied | Rebuild app after native changes; run `yarn build` in the library before packing |
|
|
225
|
+
| iOS | Not supported — Android only |
|
|
226
|
+
|
|
227
|
+
**New Architecture:** This library is a Fabric view. Ensure New Architecture is enabled in your app (required for RN 0.76+).
|
|
228
|
+
|
|
229
|
+
## Development
|
|
230
|
+
|
|
231
|
+
```sh
|
|
232
|
+
git clone https://github.com/scrollDynasty/react-native-drum-picker.git
|
|
233
|
+
cd react-native-drum-picker
|
|
234
|
+
yarn
|
|
235
|
+
yarn build
|
|
236
|
+
cd example
|
|
237
|
+
yarn android
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
From the repo root:
|
|
241
|
+
|
|
242
|
+
```sh
|
|
243
|
+
yarn lint
|
|
244
|
+
yarn build
|
|
245
|
+
yarn typecheck
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
249
|
+
|
|
250
|
+
## License
|
|
251
|
+
|
|
252
|
+
[MIT](./LICENSE) © Umar Matyokubov
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.DrumPicker = [
|
|
3
|
+
kotlinVersion: "2.0.21",
|
|
4
|
+
minSdkVersion: 24,
|
|
5
|
+
compileSdkVersion: 36,
|
|
6
|
+
targetSdkVersion: 36
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
ext.getExtOrDefault = { prop ->
|
|
10
|
+
if (rootProject.ext.has(prop)) {
|
|
11
|
+
return rootProject.ext.get(prop)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return DrumPicker[prop]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
repositories {
|
|
18
|
+
google()
|
|
19
|
+
mavenCentral()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
dependencies {
|
|
23
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
24
|
+
// noinspection DifferentKotlinGradleVersion
|
|
25
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
apply plugin: "com.android.library"
|
|
31
|
+
apply plugin: "kotlin-android"
|
|
32
|
+
|
|
33
|
+
apply plugin: "com.facebook.react"
|
|
34
|
+
|
|
35
|
+
android {
|
|
36
|
+
namespace "com.drumpicker"
|
|
37
|
+
|
|
38
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
39
|
+
|
|
40
|
+
defaultConfig {
|
|
41
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
42
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
buildFeatures {
|
|
46
|
+
buildConfig true
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
buildTypes {
|
|
50
|
+
release {
|
|
51
|
+
minifyEnabled false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
lint {
|
|
56
|
+
disable "GradleCompatible"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
compileOptions {
|
|
60
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
61
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
dependencies {
|
|
66
|
+
implementation "com.facebook.react:react-android"
|
|
67
|
+
implementation "androidx.recyclerview:recyclerview:1.4.0"
|
|
68
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
package com.drumpicker
|
|
2
|
+
|
|
3
|
+
import android.graphics.Typeface
|
|
4
|
+
import android.util.TypedValue
|
|
5
|
+
import android.view.Gravity
|
|
6
|
+
import android.view.ViewGroup
|
|
7
|
+
import android.widget.TextView
|
|
8
|
+
import androidx.recyclerview.widget.RecyclerView
|
|
9
|
+
import kotlin.math.abs
|
|
10
|
+
import kotlin.math.roundToInt
|
|
11
|
+
|
|
12
|
+
internal class DrumPickerAdapter(
|
|
13
|
+
private val defaultItemHeightPx: () -> Int,
|
|
14
|
+
) : RecyclerView.Adapter<DrumPickerAdapter.ItemViewHolder>() {
|
|
15
|
+
|
|
16
|
+
var items: List<String> = emptyList()
|
|
17
|
+
private set
|
|
18
|
+
|
|
19
|
+
var itemHeightPx: Int = 0
|
|
20
|
+
var textColor: Int = DrumPickerDefaults.TEXT_COLOR
|
|
21
|
+
var selectedTextColor: Int = DrumPickerDefaults.SELECTED_TEXT_COLOR
|
|
22
|
+
var textSizeSp: Float = DrumPickerDefaults.TEXT_SIZE_SP
|
|
23
|
+
var selectedTextSizeSp: Float = DrumPickerDefaults.SELECTED_TEXT_SIZE_SP
|
|
24
|
+
var itemBackgroundColor: Int = DrumPickerDefaults.TRANSPARENT
|
|
25
|
+
|
|
26
|
+
var distanceForPosition: ((position: Int) -> Float)? = null
|
|
27
|
+
|
|
28
|
+
private val regularTypeface = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)
|
|
29
|
+
private val selectedTypeface = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)
|
|
30
|
+
|
|
31
|
+
private fun rowHeightPx(): Int =
|
|
32
|
+
if (itemHeightPx > 0) itemHeightPx else defaultItemHeightPx()
|
|
33
|
+
|
|
34
|
+
fun updateItems(newItems: List<String>): Boolean {
|
|
35
|
+
if (newItems == items) {
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
val oldItems = items
|
|
39
|
+
items = newItems
|
|
40
|
+
when {
|
|
41
|
+
oldItems.size == newItems.size ->
|
|
42
|
+
notifyItemRangeChanged(0, newItems.size)
|
|
43
|
+
else ->
|
|
44
|
+
notifyDataSetChanged()
|
|
45
|
+
}
|
|
46
|
+
return true
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fun notifyRowMetricsChanged() {
|
|
50
|
+
if (items.isNotEmpty()) {
|
|
51
|
+
notifyItemRangeChanged(0, items.size)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override fun getItemCount(): Int = items.size
|
|
56
|
+
|
|
57
|
+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
|
|
58
|
+
val height = rowHeightPx()
|
|
59
|
+
val textView =
|
|
60
|
+
TextView(parent.context).apply {
|
|
61
|
+
gravity = Gravity.CENTER
|
|
62
|
+
includeFontPadding = false
|
|
63
|
+
setBackgroundColor(itemBackgroundColor)
|
|
64
|
+
layoutParams =
|
|
65
|
+
RecyclerView.LayoutParams(
|
|
66
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
67
|
+
height,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
return ItemViewHolder(textView)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
|
|
74
|
+
val textView = holder.textView
|
|
75
|
+
val height = rowHeightPx()
|
|
76
|
+
textView.layoutParams =
|
|
77
|
+
(textView.layoutParams as RecyclerView.LayoutParams).apply { this.height = height }
|
|
78
|
+
textView.text = items[position]
|
|
79
|
+
textView.setBackgroundColor(itemBackgroundColor)
|
|
80
|
+
holder.lastStyleBucket = Int.MIN_VALUE
|
|
81
|
+
val distance = distanceForPosition?.invoke(position) ?: 2f
|
|
82
|
+
applyItemStyle(holder, distance)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
fun applyItemStyle(holder: ItemViewHolder, distanceFromCenter: Float) {
|
|
86
|
+
val clampedDistance = abs(distanceFromCenter).coerceIn(0f, 3f)
|
|
87
|
+
val focus = (1f - clampedDistance / 3f).coerceIn(0f, 1f)
|
|
88
|
+
val bucket = (focus * 24f).roundToInt()
|
|
89
|
+
|
|
90
|
+
if (holder.lastStyleBucket == bucket) {
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
holder.lastStyleBucket = bucket
|
|
94
|
+
|
|
95
|
+
val textView = holder.textView
|
|
96
|
+
textView.alpha = 0.28f + 0.72f * focus
|
|
97
|
+
textView.setTextColor(if (focus >= 0.65f) selectedTextColor else textColor)
|
|
98
|
+
textView.setTextSize(
|
|
99
|
+
TypedValue.COMPLEX_UNIT_SP,
|
|
100
|
+
textSizeSp + (selectedTextSizeSp - textSizeSp) * focus,
|
|
101
|
+
)
|
|
102
|
+
textView.typeface = if (focus >= 0.65f) selectedTypeface else regularTypeface
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
class ItemViewHolder(val textView: TextView) : RecyclerView.ViewHolder(textView) {
|
|
106
|
+
var lastStyleBucket: Int = Int.MIN_VALUE
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
package com.drumpicker
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.WritableMap
|
|
5
|
+
import com.facebook.react.uimanager.events.Event
|
|
6
|
+
|
|
7
|
+
internal class DrumPickerChangeEvent(
|
|
8
|
+
surfaceId: Int,
|
|
9
|
+
viewId: Int,
|
|
10
|
+
private val index: Int,
|
|
11
|
+
private val value: String,
|
|
12
|
+
) : Event<DrumPickerChangeEvent>(surfaceId, viewId) {
|
|
13
|
+
|
|
14
|
+
override fun getEventName(): String = EVENT_NAME
|
|
15
|
+
|
|
16
|
+
override fun getEventData(): WritableMap =
|
|
17
|
+
Arguments.createMap().apply {
|
|
18
|
+
putInt("index", index)
|
|
19
|
+
putString("value", value)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private companion object {
|
|
23
|
+
const val EVENT_NAME = "topValueChange"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.drumpicker
|
|
2
|
+
|
|
3
|
+
import android.graphics.Color
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Visual defaults only. Row labels always come from the JS `items` prop.
|
|
7
|
+
*/
|
|
8
|
+
internal object DrumPickerDefaults {
|
|
9
|
+
const val ITEM_HEIGHT_DP = 44f
|
|
10
|
+
const val VISIBLE_ITEM_COUNT = 5
|
|
11
|
+
const val TEXT_SIZE_SP = 20f
|
|
12
|
+
const val SELECTED_TEXT_SIZE_SP = 22f
|
|
13
|
+
const val SELECTION_INDICATOR_HEIGHT_DP = 1f
|
|
14
|
+
|
|
15
|
+
val TEXT_COLOR: Int = Color.parseColor("#8E8E93")
|
|
16
|
+
val SELECTED_TEXT_COLOR: Int = Color.parseColor("#1C1C1E")
|
|
17
|
+
val SELECTION_INDICATOR_COLOR: Int = Color.parseColor("#D1D1D6")
|
|
18
|
+
val TRANSPARENT: Int = Color.TRANSPARENT
|
|
19
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package com.drumpicker
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
7
|
+
import com.facebook.react.uimanager.ViewManager
|
|
8
|
+
|
|
9
|
+
class DrumPickerViewPackage : BaseReactPackage() {
|
|
10
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
11
|
+
return listOf(DrumPickerViewManager())
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
|
|
15
|
+
|
|
16
|
+
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider { emptyMap() }
|
|
17
|
+
}
|