-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
refactor:remove mixin, ref #40
- Loading branch information
1 parent
f8a4635
commit afe0c20
Showing
12 changed files
with
432 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
import React from 'react'; | ||
import createClass from 'create-react-class'; | ||
import { View } from 'react-native'; | ||
import MultiPickerProps from './MultiPickerProps'; | ||
import MultiPickerMixin from './MultiPickerMixin'; | ||
|
||
const MultiPicker = createClass<MultiPickerProps, any>({ | ||
mixins: [MultiPickerMixin], | ||
export interface IMultiPickerProp { | ||
getValue: Function; | ||
} | ||
|
||
render() { | ||
const props = this.props; | ||
const { | ||
children, style, | ||
} = props; | ||
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), | ||
}); | ||
const MultiPicker = (props: IMultiPickerProp & MultiPickerProps) => { | ||
const { | ||
children, style, | ||
} = props; | ||
const selectedValue = props.getValue(); | ||
const colElements = React.Children.map(children, (col: any, i) => { | ||
return React.cloneElement(col, { | ||
selectedValue: selectedValue[i], | ||
onValueChange: (...args) => props.onValueChange!(i, ...args), | ||
}); | ||
return ( | ||
<View style={style}> | ||
{colElements} | ||
</View> | ||
); | ||
}, | ||
}); | ||
}); | ||
return ( | ||
<View style={style}> | ||
{colElements} | ||
</View> | ||
); | ||
}; | ||
|
||
export default MultiPicker; | ||
export default MultiPickerMixin(MultiPicker); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
import React from 'react'; | ||
import classnames from 'classnames'; | ||
import createClass from 'create-react-class'; | ||
import MultiPickerProps from './MultiPickerProps'; | ||
import MultiPickerMixin from './MultiPickerMixin'; | ||
|
||
const MultiPicker = createClass<MultiPickerProps, any>({ | ||
mixins: [MultiPickerMixin], | ||
render() { | ||
const { | ||
prefixCls, | ||
className, | ||
rootNativeProps, | ||
children, | ||
} = this.props; | ||
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), | ||
}); | ||
export interface IMultiPickerProp { | ||
getValue: Function; | ||
} | ||
|
||
const MultiPicker = (props: IMultiPickerProp & MultiPickerProps) => { | ||
const { | ||
prefixCls, | ||
className, | ||
rootNativeProps, | ||
children, | ||
style, | ||
} = props; | ||
const selectedValue = props.getValue(); | ||
const colElements = React.Children.map(children, (col: any, i) => { | ||
return React.cloneElement(col, { | ||
selectedValue: selectedValue[i], | ||
onValueChange: (...args) => props.onValueChange!(i, ...args), | ||
}); | ||
return ( | ||
<div | ||
{...rootNativeProps} | ||
style={this.props.style} | ||
className={classnames(className, prefixCls)} | ||
> | ||
{colElements} | ||
</div> | ||
); | ||
}, | ||
}); | ||
}); | ||
return ( | ||
<div | ||
{...rootNativeProps} | ||
style={style} | ||
className={classnames(className, prefixCls)} | ||
> | ||
{colElements} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MultiPicker; | ||
export default MultiPickerMixin(MultiPicker); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,39 @@ | ||
import React from 'react'; | ||
import MultiPickerProps from './MultiPickerProps'; | ||
|
||
export default { | ||
getDefaultProps() { | ||
return { | ||
export default function(ComposedComponent) { | ||
return class extends React.Component<MultiPickerProps, any> { | ||
static defaultProps = { | ||
prefixCls: 'rmc-multi-picker', | ||
onValueChange() { | ||
}, | ||
}; | ||
}, | ||
|
||
getValue() { | ||
const { children, selectedValue } = this.props; | ||
if (selectedValue && selectedValue.length) { | ||
return selectedValue; | ||
} else { | ||
if (!children) { | ||
return []; | ||
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; | ||
}); | ||
} | ||
return React.Children.map(children, (c: any) => { | ||
const cc: any = React.Children.toArray(c.props.children); | ||
return cc && cc[0] && cc[0].props.value; | ||
}); | ||
} | ||
}, | ||
|
||
onValueChange(i, v) { | ||
const value = this.getValue().concat(); | ||
value[i] = v; | ||
this.props.onValueChange(value, i); | ||
}, | ||
onValueChange = (i, v) => { | ||
const value = this.getValue().concat(); | ||
value[i] = v; | ||
this.props.onValueChange!(value, i); | ||
} | ||
|
||
render() { | ||
return ( | ||
<ComposedComponent {...this.props} getValue={this.getValue} onValueChange={this.onValueChange} /> | ||
); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.