Commit ceb35185 authored by xwenliang's avatar xwenliang

update PickerTest

parent 80cc9a3e
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#### Step 1 - install #### Step 1 - install
``` ```javascript
npm install react-native-picker --save npm install react-native-picker --save
``` ```
......
{
"presets": ["react-native"]
}
[ignore] [ignore]
; We fork some components by platform
.*/*[.]android.js
# We fork some components by platform. ; Ignore "BUCK" generated dirs
.*/*.web.js <PROJECT_ROOT>/\.buckd/
.*/*.android.js
# Some modules have their own node_modules with overlap ; Ignore unexpected extra "@providesModule"
.*/node_modules/node-haste/.* .*/node_modules/.*/node_modules/fbjs/.*
# Ugh ; Ignore duplicate module providers
.*/node_modules/babel.* ; For RN Apps installed via npm, "Libraries" folder is inside
.*/node_modules/babylon.* ; "node_modules/react-native" but in the source repo it is in the root
.*/node_modules/invariant.* .*/Libraries/react-native/React.js
# Ignore react and fbjs where there are overlaps, but don't ignore
# anything that react-native relies on
.*/node_modules/fbjs/lib/Map.js
.*/node_modules/fbjs/lib/ErrorUtils.js
# Flow has a built-in definition for the 'react' module which we prefer to use
# over the currently-untyped source
.*/node_modules/react/react.js
.*/node_modules/react/lib/React.js
.*/node_modules/react/lib/ReactDOM.js
.*/__mocks__/.*
.*/__tests__/.*
.*/commoner/test/source/widget/share.js
# Ignore commoner tests
.*/node_modules/commoner/test/.*
# See https://github.com/facebook/flow/issues/442
.*/react-tools/node_modules/commoner/lib/reader.js
# Ignore jest
.*/node_modules/jest-cli/.*
# Ignore Website
.*/website/.*
# Ignore generators
.*/local-cli/generator.*
# Ignore BUCK generated folders
.*\.buckd/
.*/node_modules/is-my-json-valid/test/.*\.json
.*/node_modules/iconv-lite/encodings/tables/.*\.json
.*/node_modules/y18n/test/.*\.json
.*/node_modules/spdx-license-ids/spdx-license-ids.json
.*/node_modules/spdx-exceptions/index.json
.*/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json
.*/node_modules/resolve/lib/core.json
.*/node_modules/jsonparse/samplejson/.*\.json
.*/node_modules/json5/test/.*\.json
.*/node_modules/ua-parser-js/test/.*\.json
.*/node_modules/builtin-modules/builtin-modules.json
.*/node_modules/binary-extensions/binary-extensions.json
.*/node_modules/url-regex/tlds.json
.*/node_modules/joi/.*\.json
.*/node_modules/isemail/.*\.json
.*/node_modules/tr46/.*\.json
; Ignore polyfills
.*/Libraries/polyfills/.*
[include] [include]
[libs] [libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow node_modules/react-native/flow/
flow/
[options] [options]
module.system=haste emoji=true
esproposal.class_static_fields=enable module.system=haste
esproposal.class_instance_fields=enable
munge_underscores=true munge_underscores=true
module.name_mapper='^image![a-zA-Z0-9$_-]+$' -> 'GlobalImageStub'
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
suppress_type=$FlowIssue suppress_type=$FlowIssue
suppress_type=$FlowFixMe suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState
suppress_type=$FixMe suppress_type=$FixMe
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-7]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-7]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
unsafe.enable_getters_and_setters=true
[version] [version]
0.24.0 ^0.57.0
...@@ -22,19 +22,32 @@ DerivedData ...@@ -22,19 +22,32 @@ DerivedData
*.xcuserstate *.xcuserstate
project.xcworkspace project.xcworkspace
# Android/IJ # Android/IntelliJ
# #
build/
.idea .idea
.gradle .gradle
local.properties local.properties
*.iml
# node.js # node.js
# #
node_modules/ node_modules/
npm-debug.log npm-debug.log
yarn-error.log
# BUCK # BUCK
buck-out/ buck-out/
\.buckd/ \.buckd/
android/app/libs *.keystore
android/keystores/debug.keystore
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/
*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots
/**
* Bootstrap of PickerTest
*/
import React, {Component} from 'react';
import {
View,
Text,
TextInput,
TouchableOpacity,
Dimensions
} from 'react-native';
import Picker from 'react-native-picker';
import area from './area.json';
export default class PickerTest extends Component {
constructor(props, context) {
super(props, context);
}
_createDateData() {
let date = [];
for(let i=1970;i<2020;i++){
let month = [];
for(let j = 1;j<13;j++){
let day = [];
if(j === 2){
for(let k=1;k<29;k++){
day.push(k+'');
}
//Leap day for years that are divisible by 4, such as 2000, 2004
if(i%4 === 0){
day.push(29+'');
}
}
else if(j in {1:1, 3:1, 5:1, 7:1, 8:1, 10:1, 12:1}){
for(let k=1;k<32;k++){
day.push(k+'');
}
}
else{
for(let k=1;k<31;k++){
day.push(k+'');
}
}
let _month = {};
_month[j+''] = day;
month.push(_month);
}
let _date = {};
_date[i+''] = month;
date.push(_date);
}
return date;
}
_createAreaData() {
let data = [];
let len = area.length;
for(let i=0;i<len;i++){
let city = [];
for(let j=0,cityLen=area[i]['city'].length;j<cityLen;j++){
let _city = {};
_city[area[i]['city'][j]['name']] = area[i]['city'][j]['area'];
city.push(_city);
}
let _data = {};
_data[area[i]['name']] = city;
data.push(_data);
}
return data;
}
_showDatePicker() {
Picker.init({
pickerData: this._createDateData(),
pickerToolBarFontSize: 16,
pickerFontSize: 16,
pickerFontColor: [255, 0 ,0, 1],
onPickerConfirm: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
},
onPickerCancel: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
},
onPickerSelect: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
}
});
Picker.show();
}
_showAreaPicker() {
Picker.init({
pickerData: this._createAreaData(),
selectedValue: ['河北', '唐山', '古冶区'],
onPickerConfirm: pickedValue => {
console.log('area', pickedValue);
},
onPickerCancel: pickedValue => {
console.log('area', pickedValue);
},
onPickerSelect: pickedValue => {
//Picker.select(['山东', '青岛', '黄岛区'])
console.log('area', pickedValue);
}
});
Picker.show();
}
_showTimePicker() {
let years = [],
months = [],
days = [],
hours = [],
minutes = [];
for(let i=1;i<51;i++){
years.push(i+1980);
}
for(let i=1;i<13;i++){
months.push(i);
hours.push(i);
}
for(let i=1;i<32;i++){
days.push(i);
}
for(let i=1;i<61;i++){
minutes.push(i);
}
let pickerData = [years, months, days, ['am', 'pm'], hours, minutes];
let date = new Date();
let selectedValue = [
date.getFullYear(),
date.getMonth()+1,
date.getDate(),
date.getHours() > 11 ? 'pm' : 'am',
date.getHours() === 12 ? 12 : date.getHours()%12,
date.getMinutes()
];
Picker.init({
pickerData,
selectedValue,
pickerTitleText: 'Select Date and Time',
wheelFlex: [2, 1, 1, 2, 1, 1],
onPickerConfirm: pickedValue => {
console.log('area', pickedValue);
},
onPickerCancel: pickedValue => {
console.log('area', pickedValue);
},
onPickerSelect: pickedValue => {
let targetValue = [...pickedValue];
if(parseInt(targetValue[1]) === 2){
if(targetValue[0]%4 === 0 && targetValue[2] > 29){
targetValue[2] = 29;
}
else if(targetValue[0]%4 !== 0 && targetValue[2] > 28){
targetValue[2] = 28;
}
}
else if(targetValue[1] in {4:1, 6:1, 9:1, 11:1} && targetValue[2] > 30){
targetValue[2] = 30;
}
// forbidden some value such as some 2.29, 4.31, 6.31...
if(JSON.stringify(targetValue) !== JSON.stringify(pickedValue)){
// android will return String all the time,but we put Number into picker at first
// so we need to convert them to Number again
targetValue.map((v, k) => {
if(k !== 3){
targetValue[k] = parseInt(v);
}
});
Picker.select(targetValue);
pickedValue = targetValue;
}
}
});
Picker.show();
}
_toggle() {
Picker.toggle();
}
_isPickerShow(){
Picker.isPickerShow(status => {
alert(status);
});
}
render() {
return (
<View style={{height: Dimensions.get('window').height}}>
<TouchableOpacity style={{marginTop: 40, marginLeft: 20}} onPress={this._showDatePicker.bind(this)}>
<Text>DatePicker</Text>
</TouchableOpacity>
<TouchableOpacity style={{marginTop: 10, marginLeft: 20}} onPress={this._showTimePicker.bind(this)}>
<Text>TimePicker</Text>
</TouchableOpacity>
<TouchableOpacity style={{marginTop: 10, marginLeft: 20}} onPress={this._showAreaPicker.bind(this)}>
<Text>AreaPicker</Text>
</TouchableOpacity>
<TouchableOpacity style={{marginTop: 10, marginLeft: 20}} onPress={this._toggle.bind(this)}>
<Text>toggle</Text>
</TouchableOpacity>
<TouchableOpacity style={{marginTop: 10, marginLeft: 20}} onPress={this._isPickerShow.bind(this)}>
<Text>isPickerShow</Text>
</TouchableOpacity>
<TextInput
placeholder="test picker with input"
style={{
height: 40,
borderColor: 'gray',
borderWidth: 1,
marginLeft: 20,
marginRight: 20,
marginTop: 10,
padding: 5
}}
/>
</View>
);
}
};
\ No newline at end of file
import 'react-native';
import React from 'react';
import App from '../App';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(
<App />
);
});
import re
# To learn about Buck see [Docs](https://buckbuild.com/). # To learn about Buck see [Docs](https://buckbuild.com/).
# To run your application with Buck: # To run your application with Buck:
# - install Buck # - install Buck
...@@ -11,8 +9,9 @@ import re ...@@ -11,8 +9,9 @@ import re
# #
lib_deps = [] lib_deps = []
for jarfile in glob(['libs/*.jar']): for jarfile in glob(['libs/*.jar']):
name = 'jars__' + re.sub(r'^.*/([^/]+)\.jar$', r'\1', jarfile) name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
lib_deps.append(':' + name) lib_deps.append(':' + name)
prebuilt_jar( prebuilt_jar(
name = name, name = name,
...@@ -20,7 +19,7 @@ for jarfile in glob(['libs/*.jar']): ...@@ -20,7 +19,7 @@ for jarfile in glob(['libs/*.jar']):
) )
for aarfile in glob(['libs/*.aar']): for aarfile in glob(['libs/*.aar']):
name = 'aars__' + re.sub(r'^.*/([^/]+)\.aar$', r'\1', aarfile) name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
lib_deps.append(':' + name) lib_deps.append(':' + name)
android_prebuilt_aar( android_prebuilt_aar(
name = name, name = name,
...@@ -28,39 +27,39 @@ for aarfile in glob(['libs/*.aar']): ...@@ -28,39 +27,39 @@ for aarfile in glob(['libs/*.aar']):
) )
android_library( android_library(
name = 'all-libs', name = "all-libs",
exported_deps = lib_deps exported_deps = lib_deps,
) )
android_library( android_library(
name = 'app-code', name = "app-code",
srcs = glob([ srcs = glob([
'src/main/java/**/*.java', "src/main/java/**/*.java",
]), ]),
deps = [ deps = [
':all-libs', ":all-libs",
':build_config', ":build_config",
':res', ":res",
], ],
) )
android_build_config( android_build_config(
name = 'build_config', name = "build_config",
package = 'com.pickertest', package = "com.pickertest",
) )
android_resource( android_resource(
name = 'res', name = "res",
res = 'src/main/res', package = "com.pickertest",
package = 'com.pickertest', res = "src/main/res",
) )
android_binary( android_binary(
name = 'app', name = "app",
package_type = 'debug', keystore = "//android/keystores:debug",
manifest = 'src/main/AndroidManifest.xml', manifest = "src/main/AndroidManifest.xml",
keystore = '//android/keystores:debug', package_type = "debug",
deps = [ deps = [
':app-code', ":app-code",
], ],
) )
...@@ -33,6 +33,13 @@ import com.android.build.OutputFile ...@@ -33,6 +33,13 @@ import com.android.build.OutputFile
* // bundleInPaidRelease: true, * // bundleInPaidRelease: true,
* // bundleInBeta: true, * // bundleInBeta: true,
* *
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives * // the root of your project, i.e. where "package.json" lives
* root: "../../", * root: "../../",
* *
...@@ -58,13 +65,17 @@ import com.android.build.OutputFile ...@@ -58,13 +65,17 @@ import com.android.build.OutputFile
* inputExcludes: ["android/**", "ios/**"], * inputExcludes: ["android/**", "ios/**"],
* *
* // override which node gets called and with what additional arguments * // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"] * nodeExecutableAndArgs: ["node"],
* *
* // supply additional arguments to the packager * // supply additional arguments to the packager
* extraPackagerArgs: [] * extraPackagerArgs: []
* ] * ]
*/ */
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/react-native/react.gradle"
/** /**
......
...@@ -50,6 +50,10 @@ ...@@ -50,6 +50,10 @@
-dontwarn com.facebook.react.** -dontwarn com.facebook.react.**
# TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
-dontwarn android.text.StaticLayout
# okhttp # okhttp
-keepattributes Signature -keepattributes Signature
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
......
package com.pickertest; package com.pickertest;
import android.app.Application; import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication; import com.facebook.react.ReactApplication;
import com.beefe.picker.PickerViewPackage; import com.beefe.picker.PickerViewPackage;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage; import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage; import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -17,7 +16,7 @@ public class MainApplication extends Application implements ReactApplication { ...@@ -17,7 +16,7 @@ public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override @Override
protected boolean getUseDeveloperSupport() { public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG; return BuildConfig.DEBUG;
} }
...@@ -28,10 +27,21 @@ public class MainApplication extends Application implements ReactApplication { ...@@ -28,10 +27,21 @@ public class MainApplication extends Application implements ReactApplication {
new PickerViewPackage() new PickerViewPackage()
); );
} }
@Override
protected String getJSMainModuleName() {
return "index";
}
}; };
@Override @Override
public ReactNativeHost getReactNativeHost() { public ReactNativeHost getReactNativeHost() {
return mReactNativeHost; return mReactNativeHost;
} }
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
} }
<resources> <resources>
<string name="app_name">PickerTest</string> <string name="app_name">PickerTest</string>
</resources> </resources>
...@@ -5,7 +5,7 @@ buildscript { ...@@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:1.3.1' classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
...@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME ...@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
keystore( keystore(
name = 'debug', name = "debug",
store = 'debug.keystore', properties = "debug.keystore.properties",
properties = 'debug.keystore.properties', store = "debug.keystore",
visibility = [ visibility = [
'PUBLIC', "PUBLIC",
], ],
) )
rootProject.name = 'PickerTest' rootProject.name = 'PickerTest'
include ':app'
include ':react-native-picker' include ':react-native-picker'
project(':react-native-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-picker/android') project(':react-native-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-picker/android')
include ':app'
{
"name": "PickerTest",
"displayName": "PickerTest"
}
\ No newline at end of file
/**
* react-native-picker example for android
*/
import './index.js';
\ No newline at end of file
/**
* react-native-picker example for ios
*/
import './index.js';
\ No newline at end of file
/** import { AppRegistry } from 'react-native';
* Bootstrap of PickerTest import PickerTest from './PickerTest';
*/
import React, {Component} from 'react';
import {
AppRegistry,
View,
Text,
TextInput,
TouchableOpacity,
Dimensions
} from 'react-native';
import Picker from 'react-native-picker';
import area from './area.json';
class PickerTest extends Component {
constructor(props, context) {
super(props, context);
}
_createDateData() {
let date = [];
for(let i=1950;i<2050;i++){
let month = [];
for(let j = 1;j<13;j++){
let day = [];
if(j === 2){
for(let k=1;k<29;k++){
day.push(k+'');
}
//Leap day for years that are divisible by 4, such as 2000, 2004
if(i%4 === 0){
day.push(29+'');
}
}
else if(j in {1:1, 3:1, 5:1, 7:1, 8:1, 10:1, 12:1}){
for(let k=1;k<32;k++){
day.push(k+'');
}
}
else{
for(let k=1;k<31;k++){
day.push(k+'');
}
}
let _month = {};
_month[j+''] = day;
month.push(_month);
}
let _date = {};
_date[i+''] = month;
date.push(_date);
}
return date;
}
_createAreaData() {
let data = [];
let len = area.length;
for(let i=0;i<len;i++){
let city = [];
for(let j=0,cityLen=area[i]['city'].length;j<cityLen;j++){
let _city = {};
_city[area[i]['city'][j]['name']] = area[i]['city'][j]['area'];
city.push(_city);
}
let _data = {};
_data[area[i]['name']] = city;
data.push(_data);
}
return data;
}
_showDatePicker() {
Picker.init({
pickerData: this._createDateData(),
pickerToolBarFontSize: 16,
pickerFontSize: 16,
pickerFontColor: [255, 0 ,0, 1],
onPickerConfirm: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
},
onPickerCancel: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
},
onPickerSelect: (pickedValue, pickedIndex) => {
console.log('date', pickedValue, pickedIndex);
}
});
Picker.show();
}
_showAreaPicker() {
Picker.init({
pickerData: this._createAreaData(),
selectedValue: ['河北', '唐山', '古冶区'],
onPickerConfirm: pickedValue => {
console.log('area', pickedValue);
},
onPickerCancel: pickedValue => {
console.log('area', pickedValue);
},
onPickerSelect: pickedValue => {
//Picker.select(['山东', '青岛', '黄岛区'])
console.log('area', pickedValue);
}
});
Picker.show();
}
_showTimePicker() {
let years = [],
months = [],
days = [],
hours = [],
minutes = [];
for(let i=1;i<51;i++){
years.push(i+1980);
}
for(let i=1;i<13;i++){
months.push(i);
hours.push(i);
}
for(let i=1;i<32;i++){
days.push(i);
}
for(let i=1;i<61;i++){
minutes.push(i);
}
let pickerData = [years, months, days, ['am', 'pm'], hours, minutes];
let date = new Date();
let selectedValue = [
[date.getFullYear()],
[date.getMonth()+1],
[date.getDate()],
[date.getHours() > 11 ? 'pm' : 'am'],
[date.getHours() === 12 ? 12 : date.getHours()%12],
[date.getMinutes()]
];
Picker.init({
pickerData,
selectedValue,
pickerTitleText: 'Select Date and Time',
wheelFlex: [2, 1, 1, 2, 1, 1],
onPickerConfirm: pickedValue => {
console.log('area', pickedValue);
},
onPickerCancel: pickedValue => {
console.log('area', pickedValue);
},
onPickerSelect: pickedValue => {
let targetValue = [...pickedValue];
if(parseInt(targetValue[1]) === 2){
if(targetValue[0]%4 === 0 && targetValue[2] > 29){
targetValue[2] = 29;
}
else if(targetValue[0]%4 !== 0 && targetValue[2] > 28){
targetValue[2] = 28;
}
}
else if(targetValue[1] in {4:1, 6:1, 9:1, 11:1} && targetValue[2] > 30){
targetValue[2] = 30;
}
// forbidden some value such as some 2.29, 4.31, 6.31...
if(JSON.stringify(targetValue) !== JSON.stringify(pickedValue)){
// android will return String all the time,but we put Number into picker at first
// so we need to convert them to Number again
targetValue.map((v, k) => {
if(k !== 3){
targetValue[k] = parseInt(v);
}
});
Picker.select(targetValue);
pickedValue = targetValue;
}
}
});
Picker.show();
}
_toggle() {
Picker.toggle();
}
_isPickerShow(){
Picker.isPickerShow(status => {
alert(status);
});
}
render() {
return (
<View style={{height: Dimensions.get('window').height}}>
<TouchableOpacity style={{marginTop: 40, marginLeft: 20}} onPress={this._showDatePicker.bind(this)}>
<Text>DatePicker</Text>
</TouchableOpacity>
<TouchableOpacity style={{marginTop: 10, marginLeft: 20}} onPress={this._showTimePicker.bind(this)}>
<Text>TimePicker</Text>
</TouchableOpacity>
<TouchableOpacity style={{marginTop: 10, marginLeft: 20}} onPress={this._showAreaPicker.bind(this)}>
<Text>AreaPicker</Text>
</TouchableOpacity>
<TouchableOpacity style={{marginTop: 10, marginLeft: 20}} onPress={this._toggle.bind(this)}>
<Text>toggle</Text>
</TouchableOpacity>
<TouchableOpacity style={{marginTop: 10, marginLeft: 20}} onPress={this._isPickerShow.bind(this)}>
<Text>isPickerShow</Text>
</TouchableOpacity>
<TextInput
placeholder="test picker with input"
style={{
height: 40,
borderColor: 'gray',
borderWidth: 1,
marginLeft: 20,
marginRight: 20,
marginTop: 10,
padding: 5
}}
/>
</View>
);
}
};
AppRegistry.registerComponent('PickerTest', () => PickerTest); AppRegistry.registerComponent('PickerTest', () => PickerTest);
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSAppTransportSecurity</key>
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "NO"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D2A28121D9B038B00D4039D"
BuildableName = "libReact.a"
BlueprintName = "React-tvOS"
ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "PickerTest-tvOS.app"
BlueprintName = "PickerTest-tvOS"
ReferencedContainer = "container:PickerTest.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
BuildableName = "PickerTest-tvOSTests.xctest"
BlueprintName = "PickerTest-tvOSTests"
ReferencedContainer = "container:PickerTest.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
BuildableName = "PickerTest-tvOSTests.xctest"
BlueprintName = "PickerTest-tvOSTests"
ReferencedContainer = "container:PickerTest.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "PickerTest-tvOS.app"
BlueprintName = "PickerTest-tvOS"
ReferencedContainer = "container:PickerTest.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "PickerTest-tvOS.app"
BlueprintName = "PickerTest-tvOS"
ReferencedContainer = "container:PickerTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
BuildableName = "PickerTest-tvOS.app"
BlueprintName = "PickerTest-tvOS"
ReferencedContainer = "container:PickerTest.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
...@@ -3,9 +3,23 @@ ...@@ -3,9 +3,23 @@
LastUpgradeVersion = "0620" LastUpgradeVersion = "0620"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "NO"
buildImplicitDependencies = "YES"> buildImplicitDependencies = "YES">
<BuildActionEntries> <BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "83CBBA2D1A601D0E00E9B192"
BuildableName = "libReact.a"
BlueprintName = "React"
ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry <BuildActionEntry
buildForTesting = "YES" buildForTesting = "YES"
buildForRunning = "YES" buildForRunning = "YES"
...@@ -37,10 +51,10 @@ ...@@ -37,10 +51,10 @@
</BuildActionEntries> </BuildActionEntries>
</BuildAction> </BuildAction>
<TestAction <TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES">
buildConfiguration = "Debug">
<Testables> <Testables>
<TestableReference <TestableReference
skipped = "NO"> skipped = "NO">
...@@ -62,15 +76,18 @@ ...@@ -62,15 +76,18 @@
ReferencedContainer = "container:PickerTest.xcodeproj"> ReferencedContainer = "container:PickerTest.xcodeproj">
</BuildableReference> </BuildableReference>
</MacroExpansion> </MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES" debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"> allowLocationSimulation = "YES">
<BuildableProductRunnable <BuildableProductRunnable
runnableDebuggingMode = "0"> runnableDebuggingMode = "0">
...@@ -86,10 +103,10 @@ ...@@ -86,10 +103,10 @@
</AdditionalOptions> </AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = "" savedToolIdentifier = ""
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES"> debugDocumentVersioning = "YES">
<BuildableProductRunnable <BuildableProductRunnable
runnableDebuggingMode = "0"> runnableDebuggingMode = "0">
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RCTBundleURLProvider.h" #import <React/RCTBundleURLProvider.h>
#import "RCTRootView.h" #import <React/RCTRootView.h>
@implementation AppDelegate @implementation AppDelegate
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
{ {
NSURL *jsCodeLocation; NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"PickerTest" moduleName:@"PickerTest"
......
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
<dict> <dict>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en</string>
<key>CFBundleDisplayName</key>
<string>PickerTest</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string> <string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
...@@ -45,7 +47,7 @@ ...@@ -45,7 +47,7 @@
<dict> <dict>
<key>localhost</key> <key>localhost</key>
<dict> <dict>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key> <key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/> <true/>
</dict> </dict>
</dict> </dict>
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#import "RCTLog.h" #import <React/RCTLog.h>
#import "RCTRootView.h" #import <React/RCTRootView.h>
#define TIMEOUT_SECONDS 600 #define TIMEOUT_SECONDS 600
#define TEXT_TO_LOOK_FOR @"Welcome to React Native!" #define TEXT_TO_LOOK_FOR @"Welcome to React Native!"
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
- (void)testRendersWelcomeScreen - (void)testRendersWelcomeScreen
{ {
UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
BOOL foundElement = NO; BOOL foundElement = NO;
......
...@@ -3,11 +3,21 @@ ...@@ -3,11 +3,21 @@
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"scripts": { "scripts": {
"start": "node_modules/react-native/packager/packager.sh" "start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
}, },
"dependencies": { "dependencies": {
"react": "15.3.1", "react": "16.0.0",
"react-native": "^0.32.0", "react-native": "^0.51.0",
"react-native-picker": "github:beefe/react-native-picker" "react-native-picker": "github:beefe/react-native-picker"
},
"devDependencies": {
"babel-jest": "21.2.0",
"babel-preset-react-native": "4.0.0",
"jest": "21.2.1",
"react-test-renderer": "16.0.0"
},
"jest": {
"preset": "react-native"
} }
} }
...@@ -4,14 +4,10 @@ import { ...@@ -4,14 +4,10 @@ import {
NativeAppEventEmitter NativeAppEventEmitter
} from 'react-native'; } from 'react-native';
let ios = Platform.OS === 'ios'; const ios = Platform.OS === 'ios';
let android = Platform.OS === 'android'; const android = Platform.OS === 'android';
let Picker = NativeModules.BEEPickerManager; const Picker = NativeModules.BEEPickerManager;
const options = {
export default {
init(options){
let opt = {
isLoop: false, isLoop: false,
pickerConfirmBtnText: 'confirm', pickerConfirmBtnText: 'confirm',
pickerCancelBtnText: 'cancel', pickerCancelBtnText: 'cancel',
...@@ -27,13 +23,19 @@ export default { ...@@ -27,13 +23,19 @@ export default {
onPickerConfirm(){}, onPickerConfirm(){},
onPickerCancel(){}, onPickerCancel(){},
onPickerSelect(){}, onPickerSelect(){},
//4.0.12 add
pickerToolBarFontSize: 16, pickerToolBarFontSize: 16,
pickerFontSize: 16, pickerFontSize: 16,
pickerFontColor: [31, 31 ,31, 1], pickerFontColor: [31, 31 ,31, 1]
...options };
export default {
init(params){
const opt = {
...options,
...params
}; };
let fnConf = { const fnConf = {
confirm: opt.onPickerConfirm, confirm: opt.onPickerConfirm,
cancel: opt.onPickerCancel, cancel: opt.onPickerCancel,
select: opt.onPickerSelect select: opt.onPickerSelect
......
{ {
"name": "react-native-picker", "name": "react-native-picker",
"version": "4.3.0", "version": "4.3.1",
"description": "A Native Picker with high performance.", "description": "A Native Picker with high performance.",
"main": "index.js", "main": "index.js",
"types": "index.d.ts", "types": "index.d.ts",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment