From cf30fbc61b077c62defeea6a918599254dd551d5 Mon Sep 17 00:00:00 2001 From: xwenliang Date: Tue, 20 Dec 2016 11:24:17 +0800 Subject: [PATCH] Fix when keyboard show and hide then picker disappear on ios #102 --- example/PickerTest/index.android.js | 9 +- example/PickerTest/index.ios.js | 9 +- example/PickerTest/index.js | 151 ++++++++++-------- ios/RCTBEEPickerManager/RCTBEEPickerManager.m | 6 +- package.json | 2 +- 5 files changed, 86 insertions(+), 91 deletions(-) diff --git a/example/PickerTest/index.android.js b/example/PickerTest/index.android.js index afea330..48d635e 100644 --- a/example/PickerTest/index.android.js +++ b/example/PickerTest/index.android.js @@ -1,11 +1,4 @@ /** * react-native-picker example for android */ - -import { - AppRegistry -} from 'react-native'; - -import PickerTest from './index.js'; - -AppRegistry.registerComponent('PickerTest', () => PickerTest); \ No newline at end of file +import './index.js'; \ No newline at end of file diff --git a/example/PickerTest/index.ios.js b/example/PickerTest/index.ios.js index a5449d9..d6eee65 100644 --- a/example/PickerTest/index.ios.js +++ b/example/PickerTest/index.ios.js @@ -1,11 +1,4 @@ /** * react-native-picker example for ios */ - -import { - AppRegistry -} from 'react-native'; - -import PickerTest from './index.js'; - -AppRegistry.registerComponent('PickerTest', () => PickerTest); +import './index.js'; \ No newline at end of file diff --git a/example/PickerTest/index.js b/example/PickerTest/index.js index 0b560a4..ba77057 100644 --- a/example/PickerTest/index.js +++ b/example/PickerTest/index.js @@ -4,83 +4,80 @@ 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'; -function 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+'日'); +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 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+'日'); + else{ + for(let k=1;k<31;k++){ + day.push(k+'日'); + } } + let _month = {}; + _month[j+'月'] = day; + month.push(_month); } - let _month = {}; - _month[j+'月'] = day; - month.push(_month); + let _date = {}; + _date[i+'年'] = month; + date.push(_date); } - let _date = {}; - _date[i+'年'] = month; - date.push(_date); + return date; } - return date; -}; - -function createAreaData(callback){ - fetch('https://raw.githubusercontent.com/beefe/react-native-picker/master/example/PickerTest/area.json').then(res => { - res.json().then(area => { - let data = []; - let len = area.length; - for(let i=0;i { - console.log(err); - }); -}; - -export default class PickerTest extends Component { - constructor(props, context) { - super(props, context); + let _data = {}; + _data[area[i]['name']] = city; + data.push(_data); + } + return data; } _showDatePicker() { Picker.init({ - pickerData: createDateData(), + pickerData: this._createDateData(), selectedValue: ['2015年', '12月', '12日'], onPickerConfirm: pickedValue => { console.log('date', pickedValue); @@ -96,22 +93,20 @@ export default class PickerTest extends Component { } _showAreaPicker() { - createAreaData(data => { - Picker.init({ - pickerData: data, - selectedValue: ['河北', '唐山', '古冶区'], - onPickerConfirm: pickedValue => { - console.log('area', pickedValue); - }, - onPickerCancel: pickedValue => { - console.log('area', pickedValue); - }, - onPickerSelect: pickedValue => { - console.log('area', pickedValue); - } - }); - Picker.show(); + Picker.init({ + pickerData: this._createAreaData(), + selectedValue: ['河北', '唐山', '古冶区'], + onPickerConfirm: pickedValue => { + console.log('area', pickedValue); + }, + onPickerCancel: pickedValue => { + console.log('area', pickedValue); + }, + onPickerSelect: pickedValue => { + console.log('area', pickedValue); + } }); + Picker.show(); } _toggle() { @@ -139,7 +134,21 @@ export default class PickerTest extends Component { isPickerShow + ); } }; + +AppRegistry.registerComponent('PickerTest', () => PickerTest); diff --git a/ios/RCTBEEPickerManager/RCTBEEPickerManager.m b/ios/RCTBEEPickerManager/RCTBEEPickerManager.m index e12d762..f2c947b 100644 --- a/ios/RCTBEEPickerManager/RCTBEEPickerManager.m +++ b/ios/RCTBEEPickerManager/RCTBEEPickerManager.m @@ -14,7 +14,7 @@ @property(nonatomic,strong)BzwPicker *pick; @property(nonatomic,assign)float height; -@property(nonatomic,strong) UIWindow * window; +@property(nonatomic,weak)UIWindow * window; @end @@ -26,7 +26,7 @@ RCT_EXPORT_MODULE(); RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ - self.window = [[UIApplication sharedApplication].windows lastObject]; + self.window = [[UIApplication sharedApplication].windows lastObject]; NSString *pickerConfirmBtnText=indic[@"pickerConfirmBtnText"]; NSString *pickerCancelBtnText=indic[@"pickerCancelBtnText"]; @@ -56,7 +56,7 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ }]; - if ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0 ){ + if ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0 ) { self.height=250; }else{ self.height=220; diff --git a/package.json b/package.json index 08b1a87..ef62caa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-picker", - "version": "4.0.10", + "version": "4.0.11", "description": "", "main": "index.js", "scripts": { -- 2.26.2