@react-native-gpui/picker 0.0.0-stage → 2.11.0-alpha.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@react-native-gpui/picker` are listed here. Each version's section becomes the notes of its GitHub release.
4
+
5
+ ## 2.11.0-alpha.1 - 2026-11-27
6
+
7
+ - First release, for `@react-native-picker/picker` 2.11.x: draws the selected item of a picker as a dropdown button. A press opens the desktop context menu of the items.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Streetwriters
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 CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ # @react-native-gpui/picker
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Adapter for [`@react-native-picker/picker`](https://github.com/react-native-picker/picker) (MIT): draws the selected item of a picker as a dropdown button. A press opens the desktop context menu of the items.
4
+
5
+ ## About
6
+
7
+ This package is the desktop adapter for [`@react-native-picker/picker`](https://github.com/react-native-picker/picker) 2.11. Install the original library next to it; its JavaScript runs unchanged on desktop, and this package provides the native side. The upstream library is licensed under the MIT license.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install @react-native-picker/picker @react-native-gpui/picker
13
+ ```
14
+
15
+ The module is autolinked on desktop.
16
+
17
+ ## Usage
18
+
19
+ ```js
20
+ import { Picker } from '@react-native-picker/picker';
21
+
22
+ <Picker selectedValue={language} onValueChange={setLanguage}>
23
+ <Picker.Item label="Java" value="java" />
24
+ <Picker.Item label="Rust" value="rust" />
25
+ </Picker>;
26
+ ```
27
+
28
+ ## Platforms
29
+
30
+ macOS is tested. Windows and Linux are not tested yet.
31
+
32
+ ## Limitations
33
+
34
+ Choosing an item calls `onValueChange` with the item's value and index, and the picker shows the selected label. `enabled`, `color`, `style` and `testID` are honored; `placeholder` is shown when nothing is selected. The Android, iOS and Windows props are ignored.
35
+
36
+ ## License
37
+
38
+ MIT. See [LICENSE](LICENSE). The upstream library, [`@react-native-picker/picker`](https://github.com/react-native-picker/picker), is MIT licensed.
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "rn-gpui-picker"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+
6
+ [dependencies]
7
+ react-native-gpui = "0.1"
8
+ # Only for DEP_RN_GPUI_CORE_RPATHS, which build.rs puts on the test binary rpath.
9
+ rn-gpui-sys = "0.1"
10
+ rn-gpui-module = "0.1"
11
+ gpui = "0.2"
12
+
13
+ [build-dependencies]
14
+ rn-gpui-module-build = "0.1"
@@ -0,0 +1,19 @@
1
+ fn main() {
2
+ rn_gpui_module_build::generate(&["../src/RNCPickerNativeComponent.ts"]);
3
+ test_rpaths();
4
+ }
5
+
6
+ /// Core's runtime is shared libraries (`libjsi.dylib`, ...). Core puts their
7
+ /// directories on the app's rpath only, so this crate's test binary gets them here.
8
+ fn test_rpaths() {
9
+ println!("cargo:rerun-if-env-changed=DEP_RN_GPUI_CORE_RPATHS");
10
+ if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
11
+ return;
12
+ }
13
+ let Ok(dirs) = std::env::var("DEP_RN_GPUI_CORE_RPATHS") else {
14
+ return;
15
+ };
16
+ for dir in dirs.split('|').filter(|dir| !dir.is_empty()) {
17
+ println!("cargo:rustc-link-arg=-Wl,-rpath,{dir}");
18
+ }
19
+ }
@@ -0,0 +1,77 @@
1
+ rn_gpui_module::include_specs!();
2
+
3
+ use std::rc::Rc;
4
+
5
+ use gpui::{div, prelude::*, px, rgba, AnyElement, MouseButton, Window};
6
+
7
+ const TEXT: u32 = 0x1f2937ff;
8
+ const BORDER: u32 = 0xd4d4d8ff;
9
+ const SURFACE: u32 = 0xffffffff;
10
+ const MUTED: u32 = 0x6b7280ff;
11
+
12
+ /// A React Native color, `0xAARRGGBB`, as GPUI's `0xRRGGBBAA`.
13
+ fn color(argb: Option<u32>, fallback: u32) -> u32 {
14
+ argb.map_or(fallback, |argb| argb.rotate_left(8))
15
+ }
16
+
17
+ pub struct Picker {
18
+ sender: Rc<RNCPickerEventSender>,
19
+ }
20
+
21
+ impl RNCPickerSpec for Picker {
22
+ fn create(_props: &RNCPickerProps, cx: &mut RNCPickerContext) -> Self {
23
+ Self {
24
+ sender: Rc::new(cx.event_sender()),
25
+ }
26
+ }
27
+
28
+ fn update(&mut self, _props: &RNCPickerProps, _changed: RNCPickerChanged, _cx: &mut RNCPickerContext) {}
29
+
30
+ fn render(&mut self, props: &RNCPickerProps, _window: &mut Window, _cx: &mut RNCPickerContext) -> AnyElement {
31
+ let items = props.items();
32
+ let selected = usize::try_from(props.selected_index()).ok();
33
+ let label = selected
34
+ .and_then(|index| items.get(index))
35
+ .map(|item| item.label().to_string())
36
+ .filter(|label| !label.is_empty())
37
+ .unwrap_or_else(|| props.placeholder().to_string());
38
+ let enabled = props.enabled();
39
+ let font_size = props.font_size().max(1.0) as f32;
40
+ let text = rgba(color(props.color(), TEXT));
41
+ let text = if label.is_empty() || selected.is_none() { rgba(color(None, MUTED)) } else { text };
42
+
43
+ let root = div()
44
+ .flex()
45
+ .flex_row()
46
+ .items_center()
47
+ .justify_between()
48
+ .size_full()
49
+ .px(px(10.0))
50
+ .rounded(px(6.0))
51
+ .border_1()
52
+ .border_color(rgba(BORDER))
53
+ .bg(rgba(SURFACE))
54
+ .opacity(if enabled { 1.0 } else { 0.5 })
55
+ .text_size(px(font_size))
56
+ .text_color(text)
57
+ .child(div().overflow_hidden().whitespace_nowrap().child(label))
58
+ .child(div().ml(px(8.0)).text_color(rgba(MUTED)).child("\u{25BE}"));
59
+
60
+ if !enabled {
61
+ return root.into_any_element();
62
+ }
63
+
64
+ let sender = self.sender.clone();
65
+ root.on_mouse_down(MouseButton::Left, move |event, _window, _cx| {
66
+ sender.rnc_picker_open(OnRNCPickerOpen {
67
+ x: f64::from(f32::from(event.position.x)),
68
+ y: f64::from(f32::from(event.position.y)),
69
+ });
70
+ })
71
+ .into_any_element()
72
+ }
73
+ }
74
+
75
+ pub fn rn_gpui_register() {
76
+ react_native_gpui::host_component::register_component(rnc_picker_component::<Picker>());
77
+ }
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@react-native-gpui/picker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.11.0-alpha.1",
4
+ "description": "Adapter for @react-native-picker/picker (MIT): a dropdown picker that opens a desktop context menu",
5
+ "license": "MIT",
6
+ "main": "src/index.ts",
7
+ "files": [
8
+ "src",
9
+ "desktop",
10
+ "react-native.config.js",
11
+ "README.md",
12
+ "CHANGELOG.md",
13
+ "LICENSE"
14
+ ],
15
+ "codegenConfig": {
16
+ "name": "RNGpuiPickerSpec",
17
+ "type": "all",
18
+ "jsSrcsDir": "src"
19
+ },
20
+ "peerDependencies": {
21
+ "react-native": "0.87.x",
22
+ "@react-native-gpui/core": ">=0.87.0-alpha.0 <0.88.0",
23
+ "@react-native-picker/picker": "2.11.x"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/streetwriters/react-native-gpui-modules.git",
28
+ "directory": "modules/picker"
29
+ },
30
+ "homepage": "https://github.com/streetwriters/react-native-gpui-modules/tree/main/modules/picker#readme",
31
+ "bugs": {
32
+ "url": "https://github.com/streetwriters/react-native-gpui-modules/issues"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "tag": "latest"
37
+ }
38
+ }
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ dependency: {
3
+ platforms: {
4
+ desktop: {
5
+ crate: 'rn-gpui-picker',
6
+ hostComponents: [{ name: 'RNCPicker' }],
7
+ sourceOverrides: {
8
+ '@react-native-picker/picker/js/Picker.js': './src/Picker.desktop.js',
9
+ },
10
+ },
11
+ },
12
+ },
13
+ };
@@ -0,0 +1,68 @@
1
+ import React, { Component } from 'react';
2
+ import { ContextMenu } from '@react-native-gpui/core/desktop';
3
+ import NativePicker from './RNCPickerNativeComponent';
4
+
5
+ class PickerItem extends Component {
6
+ render() {
7
+ throw null;
8
+ }
9
+ }
10
+
11
+ export default class Picker extends Component {
12
+ static Item = PickerItem;
13
+
14
+ openMenu = async ({ x, y }) => {
15
+ const { enabled = true, onValueChange } = this.props;
16
+ if (!enabled) return;
17
+ const items = this.items();
18
+ const id = await ContextMenu.show(
19
+ items.map((item, index) => ({ id: String(index), label: item.label })),
20
+ { x, y },
21
+ );
22
+ if (id == null) return;
23
+ const index = Number(id);
24
+ const item = items[index];
25
+ if (item && onValueChange) {
26
+ onValueChange(item.value, index);
27
+ }
28
+ };
29
+
30
+ items() {
31
+ return React.Children.toArray(this.props.children)
32
+ .filter(child => React.isValidElement(child))
33
+ .map(child => ({
34
+ label: String(child.props.label),
35
+ value: child.props.value ?? child.props.label,
36
+ testID: child.props.testID,
37
+ }));
38
+ }
39
+
40
+ render() {
41
+ const {
42
+ style,
43
+ selectedValue,
44
+ enabled = true,
45
+ color,
46
+ placeholder,
47
+ testID,
48
+ accessibilityLabel,
49
+ } = this.props;
50
+ const items = this.items();
51
+ const selectedIndex = items.findIndex(item => item.value === selectedValue);
52
+
53
+ return React.createElement(NativePicker, {
54
+ style: [{ minHeight: 32 }, style],
55
+ items: items.map(({ label, testID: itemTestID }) => ({
56
+ label,
57
+ testID: itemTestID,
58
+ })),
59
+ selectedIndex,
60
+ enabled,
61
+ color: color,
62
+ placeholder,
63
+ testID,
64
+ accessibilityLabel,
65
+ onRNCPickerOpen: event => this.openMenu(event.nativeEvent),
66
+ });
67
+ }
68
+ }
@@ -0,0 +1,27 @@
1
+ import type { ColorValue, HostComponent, ViewProps } from 'react-native';
2
+ import { codegenNativeComponent } from 'react-native';
3
+ import type { CodegenTypes } from 'react-native';
4
+
5
+ export type PickerItem = Readonly<{
6
+ label: string;
7
+ testID?: string;
8
+ }>;
9
+
10
+ export type OpenEvent = Readonly<{
11
+ x: CodegenTypes.Double;
12
+ y: CodegenTypes.Double;
13
+ }>;
14
+
15
+ export interface NativeProps extends ViewProps {
16
+ items: ReadonlyArray<PickerItem>;
17
+ selectedIndex?: CodegenTypes.WithDefault<CodegenTypes.Int32, -1>;
18
+ enabled?: CodegenTypes.WithDefault<boolean, true>;
19
+ color?: ColorValue;
20
+ fontSize?: CodegenTypes.WithDefault<CodegenTypes.Double, 14>;
21
+ placeholder?: string;
22
+ onRNCPickerOpen?: CodegenTypes.DirectEventHandler<OpenEvent>;
23
+ }
24
+
25
+ export default codegenNativeComponent<NativeProps>('RNCPicker', {
26
+ interfaceOnly: true,
27
+ }) as HostComponent<NativeProps>;
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {};