Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

升级WheelPicker到最新版,暴露更多方法 Upgrade WheelPicker to the latest version,exposed more method #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/dictionaries/yatesmiao.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

471 changes: 471 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

204 changes: 126 additions & 78 deletions WheelCurvedPicker.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,140 @@

import React from 'react';
import {
View,
ColorPropType,
requireNativeComponent,
View,
ColorPropType,
requireNativeComponent,
} from 'react-native';


var WheelCurvedPicker = React.createClass ({

propTypes: {
...View.propTypes,

data: React.PropTypes.array,

textColor: ColorPropType,

textSize: React.PropTypes.number,

itemStyle: React.PropTypes.object,

itemSpace: React.PropTypes.number,

onValueChange: React.PropTypes.func,

selectedValue: React.PropTypes.any,

selectedIndex: React.PropTypes.number,
},

getDefaultProps(): Object {
return {
itemStyle : {color:"white", fontSize:26},
itemSpace: 20,
};
},

getInitialState: function() {
return this._stateFromProps(this.props);
},

componentWillReceiveProps: function(nextProps) {
this.setState(this._stateFromProps(nextProps));
},

_stateFromProps: function(props) {
var selectedIndex = 0;
var items = [];
React.Children.forEach(props.children, function (child, index) {
if (child.props.value === props.selectedValue) {
selectedIndex = index;
}
items.push({value: child.props.value, label: child.props.label});
});

var textSize = props.itemStyle.fontSize
var textColor = props.itemStyle.color

return {selectedIndex, items, textSize, textColor};
},

_onValueChange: function(e: Event) {
if (this.props.onValueChange) {
this.props.onValueChange(e.nativeEvent.data);
}
},

render() {
return <WheelCurvedPickerNative
{...this.props}
onValueChange={this._onValueChange}
data={this.state.items}
textColor={this.state.textColor}
textSize={this.state.textSize}
selectedIndex={parseInt(this.state.selectedIndex)} />;
}
propTypes: {
...View.propTypes,

data: React.PropTypes.array,

selectedIndex: React.PropTypes.number,

selectTextColor: ColorPropType,

itemStyle: React.PropTypes.object, //textColor textSize

textSize: React.PropTypes.number,
textColor: ColorPropType,

// 设置滚轮选择器指示器样式
indicatorStyle: React.PropTypes.object, //indicatorColor indicatorSize

indicatorSize: React.PropTypes.number,
indicatorColor: ColorPropType,

// 设置滚轮选择器是否显示指示器
indicator: React.PropTypes.bool,

// 设置滚轮选择器是否显示幕布
curtain: React.PropTypes.bool,
// 设置滚轮选择器幕布颜色
curtainColor: ColorPropType,

// 设置滚轮选择器是否有空气感
atmospheric: React.PropTypes.bool,

// 滚轮选择器是否开启卷曲效果
curved: React.PropTypes.bool,

// 设置滚轮选择器可见数据项数量
visibleItemCount: React.PropTypes.number,

itemSpace: React.PropTypes.number,

onValueChange: React.PropTypes.func,

selectedValue: React.PropTypes.any,

},

getDefaultProps(): Object {
return {
itemStyle : {color:"white", fontSize:26},
indicatorStyle: {color:"red", fontSize:2},
itemSpace: 20,
};
},

getInitialState: function() {
return this._stateFromProps(this.props);
},

componentWillReceiveProps: function(nextProps) {
this.setState(this._stateFromProps(nextProps));
},

_stateFromProps: function(props) {
var selectedIndex = 0;
var items = [];
React.Children.forEach(props.children, function (child, index) {
if (child.props.value === props.selectedValue) {
selectedIndex = index;
}
items.push({value: index, theValue: child.props.value, label: child.props.label});
});

var textSize = props.itemStyle.fontSize
var textColor = props.itemStyle.color
var selectTextColor = props.selectTextColor
var itemSpace = props.itemSpace
var indicator = props.indicator
var indicatorColor = props.indicatorStyle.color
var indicatorSize = props.indicatorStyle.fontSize
var curtain = props.curtain
var curtainColor = props.curtainColor
var atmospheric = props.atmospheric
var curved = props.curved
var visibleItemCount = props.visibleItemCount

return {selectedIndex, items, textSize, textColor, selectTextColor, itemSpace,indicator, indicatorColor, indicatorSize, curtain, curtainColor, atmospheric, curved, visibleItemCount} ;
},

_onValueChange: function(e: Event) {
if (this.props.onValueChange) {
var selectedItem = this.state.items[e.nativeEvent.data];
!selectedItem && (selectedItem = {theValue:0});
this.props.onValueChange(selectedItem.theValue);
}
},

render() {
return <WheelCurvedPickerNative
{...this.props}
onValueChange={this._onValueChange}
data={this.state.items}
selectedIndex={parseInt(this.state.selectedIndex)}
textColor={this.state.textColor}
textSize={this.state.textSize}
selectTextColor={this.state.selectTextColor}
itemSpace={this.state.itemSpace}
indicator={this.state.indicator}
indicatorColor={this.state.indicatorColor}
indicatorSize={this.state.indicatorSize}
curtain={this.state.curtain}
atmospheric={this.state.atmospheric}
curved={this.state.curved}
visibleItemCount={this.state.visibleItemCount}
/>;
}
});

WheelCurvedPicker.Item = React.createClass({
propTypes: {
value: React.PropTypes.any, // string or integer basically
label: React.PropTypes.string,
},

render: function() {
// These items don't get rendered directly.
return null;
},
propTypes: {
value: React.PropTypes.any, // string or integer basically
label: React.PropTypes.string,
},

render: function() {
// These items don't get rendered directly.
return null;
},
});

var WheelCurvedPickerNative = requireNativeComponent('WheelCurvedPicker', WheelCurvedPicker);
Expand Down
6 changes: 4 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
Expand All @@ -16,6 +16,8 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "cn.aigestudio.wheelpicker:WheelPicker:1.0.3"
// compile "cn.aigestudio.wheelpicker:WheelPicker:1.0.3"
compile 'cn.aigestudio.wheelpicker:WheelPicker:1.1.2'

compile 'com.facebook.react:react-native:+'
}
59 changes: 33 additions & 26 deletions android/src/main/java/com/zyu/ReactWheelCurvedPicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import android.os.SystemClock;
import android.util.AttributeSet;

import com.aigestudio.wheelpicker.core.AbstractWheelPicker;
import com.aigestudio.wheelpicker.view.WheelCurvedPicker;
import com.aigestudio.wheelpicker.WheelPicker;
import com.aigestudio.wheelpicker.WheelPicker;
import com.aigestudio.wheelpicker.WheelPicker.OnWheelChangeListener;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
Expand All @@ -23,61 +24,67 @@
/**
* @author <a href="mailto:[email protected]"> Sam Yu </a>
*/
public class ReactWheelCurvedPicker extends WheelCurvedPicker {

public class ReactWheelCurvedPicker extends WheelPicker {
// private Integer indicatorColor = Color.WHITE;
private final EventDispatcher mEventDispatcher;
private List<Integer> mValueData;

private int mState;
// public void setIndicatorColor(Integer indicatorColor) {
// this.indicatorColor = indicatorColor;
// }
public ReactWheelCurvedPicker(ReactContext reactContext) {
super(reactContext);
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
setOnWheelChangeListener(new OnWheelChangeListener() {
@Override
public void onWheelScrolling(float deltaX, float deltaY) {
public void onWheelScrolled(int offset) {
}

@Override
public void onWheelSelected(int index, String data) {
if (mValueData != null && index < mValueData.size()) {
public void onWheelSelected(int position) {
if (mValueData != null && position < mValueData.size()) {
mEventDispatcher.dispatchEvent(
new ItemSelectedEvent(getId(), mValueData.get(index)));
new ItemSelectedEvent(getId(), mValueData.get(position)));
}
}

@Override
public void onWheelScrollStateChanged(int state) {
mState = state;
}
});
}

// @Override
// protected void drawForeground(Canvas canvas) {
// super.drawForeground(canvas);
//
// Paint paint = new Paint();
// paint.setColor(this.indicatorColor);
// canvas.drawLine(rectCurItem.left, rectCurItem.top, rectCurItem.right, rectCurItem.top, paint);
// canvas.drawLine(rectCurItem.left, rectCurItem.bottom, rectCurItem.right, rectCurItem.bottom, paint);
// }
@Override
protected void drawForeground(Canvas canvas) {
super.drawForeground(canvas);

Paint paint = new Paint();
paint.setColor(Color.WHITE);
int colorFrom = 0x00FFFFFF;//Color.BLACK;
int colorTo = Color.WHITE;
LinearGradient linearGradientShader = new LinearGradient(rectCurItem.left, rectCurItem.top, rectCurItem.right/2, rectCurItem.top, colorFrom, colorTo, Shader.TileMode.MIRROR);
paint.setShader(linearGradientShader);
canvas.drawLine(rectCurItem.left, rectCurItem.top, rectCurItem.right, rectCurItem.top, paint);
canvas.drawLine(rectCurItem.left, rectCurItem.bottom, rectCurItem.right, rectCurItem.bottom, paint);
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

@Override
public void setItemIndex(int index) {
super.setItemIndex(index);
unitDeltaTotal = 0;
mHandler.post(this);
}
// @Override
// public void setItemIndex(int index) {
// super.setItemIndex(index);
// unitDeltaTotal = 0;
// mHandler.post(this);
// }

public void setValueData(List<Integer> data) {
mValueData = data;
}

public int getState() {
return state;
return mState;
}

}

class ItemSelectedEvent extends Event<ItemSelectedEvent> {
Expand Down
Loading