Code Monkey home page Code Monkey logo

m-picker's Introduction

rmc-picker


React Mobile Picker Component (web and react-native)

NPM version react-native react build status Test coverage gemnasium deps npm download

Screenshots

Development

npm i
npm start

Example

http://localhost:8000/examples/

online example: http://react-component.github.io/m-picker/

react-native

npm run rn-init
npm run watch-tsc
react-native start
react-native run-ios

install

rmc-picker

4.x beta docs

If you are looking for 3.x doc, please see [email protected]

Usage

<MultiPicker
  selectedValue={this.state.value}
  onValueChange={this.onChange}
>
  <Picker indicatorClassName="my-picker-indicator">
    <Picker.Item className="my-picker-view-item" value="1">one</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="2">two</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="3">three</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="4">four</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="5">five</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="6">six</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="7">seven</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="8">eight</Picker.Item>
  </Picker>
  <Picker indicatorClassName="my-picker-indicator">
    <Picker.Item className="my-picker-view-item" value="11">eleven</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="12">twelve</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="13">thirteen</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="14">fourteen</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="15">fifteen</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="16">sixteen</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="17">seventeen</Picker.Item>
    <Picker.Item className="my-picker-view-item" value="18">eighteen</Picker.Item>
  </Picker>
</MultiPicker>

API

MultiPicker props

name description type default
className(web) additional css class of root dom node String
prefixCls(web) prefix class String ''
defaultSelectedValue(web) default selected values string[]/number[]
selectedValue current selected values string[]/number[]
onValueChange fire when picker change Function(value)

Picker props

name description type default
className(web) additional css class of root dom node String
prefixCls(web) prefix class String ''
defaultSelectedValue(web) default selected values string/number
selectedValue current selected values string/number
onValueChange fire when picker change Function(value)
disabled whether picker is disabled bool false
indicatorClassName className of indicator String
indicatorStyle style of indicator object

Picker.Item props

name description type default
className(web) additional css class of root dom node String
value value of item String

Test Case

npm test
npm run chrome-test

Coverage

npm run coverage

open coverage/ dir

License

rmc-picker is released under the MIT license.

m-picker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

m-picker's Issues

初始化时不会触发onValueChange事件

复现代码

function App() {
  const [value, setValue] = useState([]);

  const onChange = value => {
    console.log(value);
    setValue(value);
  };
  return (
    <div className="App">
      <MultiPicker selectedValue={value} onValueChange={onChange}>
        <Picker indicatorClassName="my-picker-indicator">
          <Picker.Item className="my-picker-view-item" value="1">
            one
          </Picker.Item>
        </Picker>
      </MultiPicker>
    </div>
  );
}

期待效果
初始化时触发onValueChange事件

React Native - TSC Support - Platform Specific Typings

Typescript definition file conflicts.

Platform: React Native
Scripting: Typescript

import Picker, { Popup } from "rmc-picker";

// TSC Compile Error. 
[ts] Module '"/doeworks/src/mobile/node_modules/rmc-picker/lib"' has no exported member 'Popup'. [2305]

Select value on click/tap

Hi!

Is there a way to select the value on click on each item? I'm not familiar with ZScroller, but it seems like it eats all the click event for the items

Picker.Item undefined

simulator screen shot - iphone 8 plus - 2018-03-16 at 17 53 19
import * as React from 'react'
import { TextInput, View, Text } from 'react-native'
// import RMCMultiPicker from 'rmc-picker/lib/MultiPicker'
// import RMCPicker from 'rmc-picker/lib/Picker'
import Picker from 'rmc-picker/lib/NativePicker'
// import { Toast } from 'antd-mobile'
// const Item = RMCPicker.Item
// const { Item } = RMCPicker
export default class DropPicker extends React.Component<any, any> {
state = {
value: [],
}
render() {
let value = 1
let data = [1, 2, 3, 4]
return (

<View style={{ flex: 1 }}>

{data.map(item => (
<Picker.Item key={'item'} value={'item'} label={'fdfdf'}>
{item}
</Picker.Item>
))}


{/* <RMCPicker.Item value="2">two</RMCPicker.Item>
<RMCPicker.Item value="3">three</RMCPicker.Item>
<RMCPicker.Item value="4">four</RMCPicker.Item>
<RMCPicker.Item value="5">five</RMCPicker.Item>
<RMCPicker.Item value="6">six</RMCPicker.Item>
<RMCPicker.Item value="7">seven</RMCPicker.Item>
<RMCPicker.Item value="8">eight</RMCPicker.Item> */}

)
}
}

Bug: if props are updated except selectedValue, Picker's selectedValue will have the value of first Picker.Item.

{/* if component props will be changed like below. */}

<Picker
  defaultSelectedValue={0}
  selectedValue={someAwaitingValue /* it is undefined yet. */}
>
  {items}
</Picker>

{/* vvvvvvvvvv */}

<Picker
  defaultSelectedValue={1}
  selectedValue={someAwaitingValue /* it is undefined yet. */}
>
  {items}
</Picker>

The condition for updating this.state.selectedValue is currently 'selectedValue' in nextProps.
This causes select method will update the selectedValue to be the first value of Picker.Item.

split scroller

怎么不把 scroller 拆分出来?现在杂糅到一起看着维护成本略高,以及兼容性成本。

4.0 版本不支持 preact

引入 Picker.Item 方式之后每行的文本为空,可能和 react 和 preact 的 props.children 的机制不一致有关系。

适配preact

preact对于children处理较弱,某些情况会在children为[]时转换为undefined,导致undefined.map和 for循环 等代码报错。

react中使用报错Uncaught TypeError: Cannot read property 'Item' of undefined,如何解决

import { MultiPicker, Picker} from 'rmc-picker';
---
<div style={{ background: '#f5f5f9', padding: 10 }}>
            <MultiPicker
              selectedValue={this.state.value}
              onValueChange={this.onChange}
              onScrollChange={this.onScrollChange}
            >
              <Picker indicatorClassName="my-picker-indicator">
                <Picker.Item className="my-picker-view-item" value="1">one</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="2">two</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="3">three</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="4">four</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="5">five</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="6">six</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="7">seven</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="8">eight</Picker.Item>
              </Picker>
              <Picker indicatorClassName="my-picker-indicator">
                <Picker.Item className="my-picker-view-item" value="11">eleven</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="12">twelve</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="13">thirteen</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="14">fourteen</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="15">fifteen</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="16">sixteen</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="17">seventeen</Picker.Item>
                <Picker.Item className="my-picker-view-item" value="18">eighteen</Picker.Item>
              </Picker>
            </MultiPicker>
          </div>
app.bundle.js:189551 Uncaught TypeError: Cannot read property 'Item' of undefined
    at Object.<anonymous> (app.bundle.js:189551)
    at __webpack_require__ (app.bundle.js:1299)
    at fn (app.bundle.js:722)
    at Object.<anonymous> (app.bundle.js:181898)
    at __webpack_require__ (app.bundle.js:1299)
    at fn (app.bundle.js:722)
    at Object.<anonymous> (app.bundle.js:75501)
    at __webpack_require__ (app.bundle.js:1299)
    at fn (app.bundle.js:722)
    at Object.<anonymous> (app.bundle.js:283796)

Popup和Picker结合使用时,.getValue()报错,picker对象中没有此方法? this.props.onOk!(this.picker && this.picker.getValue())

PopupMixin.tsx line:116

Popup和Picker结合使用时,.getValue()报错,picker对象中没有此方法?

import Picker from 'rmc-picker/lib/Picker'
import PopPicker from "rmc-picker/lib/Popup";

...
    const items = ["1", "2", "3", "4", "5" ,"6" ,"7"];
    const popupContent = (
      <Picker
      >
        {
          items.map((item) => {
            return <Picker.Item value={item} key={generateUUID()}>
            {item}
            </Picker.Item>
          })
        }
      </Picker>
    );
    
   const picker = (
        <PopPicker
          transitionName="rmc-picker-popup-slide-fade"
          maskTransitionName="rmc-picker-popup-fade"
          picker={popupContent}
          okText="OK"
          dismissText="取消"
          title="选择"
          value={value}
          pickerValueChangeProp="onValueChange"
          pickerValueProp="selectedValue"
          onOk={this.handleSelectChange}
        >
          <div >
            <div >
              <span>{value}</span>
              <span>
                <Icon type="down" theme="outlined" />
              </span>
            </div>
          </div>
        </PopPicker>
);
...

How to programatically opens the popup

In the example, there is a button inside the popup component, when button is clicked, popup shows.
How can the popup be opened by event other than the click of a button?

3.8.*and 3.9.*不兼容

3.8.7引入后lib文件夹里有index.web.js!但是3.9.1 lib文件夹中没有index.js
导致不兼容问题

每个item能不能支持html标签?因为我想在每个item中增加不同的显示文字,比如星期,并设置样式

如下代码,主要是想在map的地方增加dangerouslySetInnerHTML

const map = (item: any) => {
      const { className = '', style, value } = item.props;
      return (
        <div
          style={{ ...itemStyle, ...style }}
          className={`${selectedValue === value ? selectedItemClassName : itemClassName} ${className}`}
          key={value}
          dangerouslySetInnerHTML={{__html: item.children || item.props.children }}
        >
    
        </div>
      );
    };

MultiPicker logic incorrect, when not set selectedValue.

If not set selectedValue, is no has event fire when reselect the first item.

core code:

MultiPicker.tsx:

    const selectedValue = this.getValue();
    const colElements = React.Children.map(children, (col: any, i) => {
      return React.cloneElement(col, {
        selectedValue: selectedValue[i],
        onValueChange: (...args) => this.onValueChange(i, ...args),
      });
    });

the getValue implement in MultiPickerMixin.tsx:

  getValue() {
    const { children, selectedValue } = this.props;
    if (selectedValue && selectedValue.length) {
      return selectedValue;
    } else {
      if (!children) {
        return [];
      }
      return React.Children.map(children, (c: any) => {
        const cc: any = React.Children.toArray(c.props.children);
        return cc && cc[0] && cc[0].props.value;
      });
    }
  },

If not set selectedValue, the result of getValue() alway equel the first item's value of picker's children of multipicker.

Remove zscroller

zscroller 已经成为影响“体积”和“复杂度”的最后一个大因素,被 Picker / ListView / Calendar 三个组件用到,分别都导致了一定的代码冗余、理解复杂度等问题。

以 Picker 为例、对比社区其他 UI 库做法:

原生实现的 framework7 picker https://github.com/framework7io/Framework7/blob/9f3589b2a2dc9d2119d41887a31309c8e811ec27/src/js/framework7/picker.js
基于 angular 的 ionic picker https://github.com/ionic-team/ionic/blob/1573043f4e31cabe1bed6bb0f4b171a8575d360d/src/components/picker/picker-column.ts

基于 zepto 的 weui picker https://github.com/Tencent/weui.js/blob/81deb5c1c3da3e7d4d5d124d4c5da100171b8408/src/picker/picker.js
基于 react 的 weui picker https://github.com/weui/react-weui/blob/f8b12cd6f383b3e07c64442623839376384e33d0/src/components/picker/picker.js
基于 vue 的 饿了么 picker https://github.com/ElemeFE/mint-ui/blob/28abcb96cd6f85fae0863b36ef8a24cacf7f721e/packages/picker/src/picker.vue
这三个压缩后体积都在 10k 左右,并且源码比较清晰无复杂依赖,没有多余代码。

发现一个和我们一样使用 zscroller 的 picker https://github.com/airyland/vux/blob/e3f46841a544984d1d93a8e3bcf86a03b7f38f3b/src/components/picker/scroller.js 也精简了不少代码。

我们目前的问题主要出在 zscroller 上、导致体积是他们的 2 倍多大小,zscroller 的 zoom / enableScrollX / paging / PullToRefresh 这些 增加代码行数、又增加复杂度,对组件来说也是多余代码。

请求支持下点击选择

期望效果是,不仅能支持滑动选择,还能支持点击选择,不然每次都要滑动,太麻烦了

MultiPicker React-Native 0.42 breaks with example

MultiPicker doesn't seem to work on RN 0.42. It breaks on the example provided.

Console.log provided below.

Expected a component class, got [object Object].handleException @ ExceptionsManager.js:63handleError @ InitializeCore.js:114reportFatalError @ error-guard.js:44guard @ MessageQueue.js:48callFunctionReturnFlushedQueue @ MessageQueue.js:107message @ index.js:73 ExceptionsManager.js:71 Warning: Exception thrown by hook while handling onSetChildren: Invariant Violation: Expected onMountComponent() to fire for the child before its parent includes it in onSetChildren(). Invariant Violation: Expected onMountComponent() to fire for the child before its parent includes it in onSetChildren(). at invariant (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:2210:7) at Object.onSetChildren (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:4623:58) at callHook (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8194:4) at emitEvent (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8211:1) at Object.onSetChildren (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:8498:1) at Constructor.setChildrenForInstrumentation (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:18282:32) at Constructor._updateChildren (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:18538:31) at Constructor.updateChildren (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:18454:6) at Constructor.receiveComponent (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:15284:6) at Object.receiveComponent (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false:17561:18)reactConsoleErrorHandler @ ExceptionsManager.js:71console.error @ YellowBox.js:61printWarning @ warning.js:36warning @ warning.js:60callHook @ ReactDebugTool.js:72emitEvent @ ReactDebugTool.js:87onSetChildren @ ReactDebugTool.js:374setChildrenForInstrumentation @ ReactMultiChild.js:159_updateChildren @ ReactMultiChild.js:415updateChildren @ ReactMultiChild.js:331receiveComponent @ ReactNativeBaseComponent.js:130receiveComponent @ ReactReconciler.js:163_updateRenderedComponent @ ReactCompositeComponent.js:981_performComponentUpdate @ ReactCompositeComponent.js:944updateComponent @ ReactCompositeComponent.js:846receiveComponent @ ReactCompositeComponent.js:709receiveComponent @ ReactReconciler.js:163_updateRenderedComponent @ ReactCompositeComponent.js:981_performComponentUpdate @ ReactCompositeComponent.js:944updateComponent @ ReactCompositeComponent.js:846performUpdateIfNecessary @ ReactCompositeComponent.js:734performUpdateIfNecessary @ ReactReconciler.js:213runBatchedUpdates @ ReactUpdates.js:170perform @ Transaction.js:149perform @ Transaction.js:149perform @ ReactUpdates.js:95flushBatchedUpdates @ ReactUpdates.js:199closeAll @ Transaction.js:222perform @ Transaction.js:163batchedUpdates @ ReactDefaultBatchingStrategy.js:65enqueueUpdate @ ReactUpdates.js:227enqueueUpdate @ ReactUpdateQueue.js:23enqueueSetState @ ReactUpdateQueue.js:247ReactComponent.setState @ ReactComponent.js:63(anonymous function) @ tab-bar-item-ios.js:30tryCallOne @ core.js:37(anonymous function) @ core.js:123(anonymous function) @ JSTimers.js:100callTimer @ JSTimersExecution.js:95callImmediatesPass @ JSTimersExecution.js:199callImmediates @ JSTimersExecution.js:214(anonymous function) @ MessageQueue.js:214guard @ MessageQueue.js:46__callImmediates @ MessageQueue.js:214(anonymous function) @ MessageQueue.js:128guard @ MessageQueue.js:46invokeCallbackAndReturnFlushedQueue @ MessageQueue.js:126message @ index.js:73 ExceptionsManager.js:71 Unhandled JS Exception: Expected a component class, got [object Object].reactConsoleErrorHandler @ ExceptionsManager.js:71console.error @ YellowBox.js:61logIfNoNativeHook @ RCTLog.js:38__callFunction @ MessageQueue.js:236(anonymous function) @ MessageQueue.js:108guard @ MessageQueue.js:46callFunctionReturnFlushedQueue @ MessageQueue.js:107message @ index.js:73

OnClick handler for Picker

ref ant-design/ant-design-mobile#1841

What problem does this feature solve?

The user can change the value of the Picker/ PickerView/ DatePicker by clicking the value and scroll to that value besides scrolling the picker.

What does the proposed API look like?

<Picker onPickerClick={(value) => console.log(value) />

onPickerClick will return the value that is clicked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.