-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
148 additions
and
165 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,65 @@ | ||
import React from 'react'; | ||
import { | ||
ImageStyle, | ||
StyleProp, | ||
StyleSheet, | ||
Text, | ||
TouchableWithoutFeedback, | ||
View, | ||
ViewStyle, | ||
} from 'react-native'; | ||
import { ImageStyle, StyleProp, Text, TouchableWithoutFeedback, View, ViewStyle } from 'react-native'; | ||
import { WithTheme, WithThemeStyles } from '../style'; | ||
import Checkbox from './Checkbox'; | ||
import { CheckboxPropsType } from './PropsType'; | ||
import AgreeItemstyle, { ICheckboxStyle } from './style/index'; | ||
import AgreeItemstyles, { CheckboxStyle } from './style/index'; | ||
|
||
const refCheckbox = 'checkbox'; | ||
|
||
export interface AgreeItemNativeProps extends CheckboxPropsType { | ||
styles?: ICheckboxStyle; | ||
export interface AgreeItemProps | ||
extends CheckboxPropsType, | ||
WithThemeStyles<CheckboxStyle> { | ||
checkboxStyle?: StyleProp<ImageStyle>; | ||
style?: StyleProp<ViewStyle>; | ||
} | ||
|
||
const AgreeItemstyles = StyleSheet.create<any>(AgreeItemstyle); | ||
|
||
export default class AgreeItem extends React.Component< | ||
AgreeItemNativeProps, | ||
any | ||
> { | ||
static defaultProps = { | ||
styles: AgreeItemstyles, | ||
}; | ||
export default class AgreeItem extends React.Component<AgreeItemProps, any> { | ||
checkbox: Checkbox | null; | ||
|
||
handleClick = () => { | ||
const checkBox: Checkbox = this.refs[refCheckbox] as Checkbox; | ||
checkBox.handleClick(); | ||
} | ||
if (this.checkbox) { | ||
this.checkbox.handleClick(); | ||
} | ||
}; | ||
|
||
render(): JSX.Element { | ||
// tslint:disable:prefer-const | ||
let { | ||
render() { | ||
const { | ||
style, | ||
checkboxStyle, | ||
children, | ||
disabled, | ||
checked, | ||
defaultChecked, | ||
onChange, | ||
styles, | ||
} = this.props; | ||
styles = styles!; | ||
|
||
let contentDom = !children ? null : React.isValidElement(children) ? ( | ||
children | ||
) : ( | ||
<Text>{children}</Text> | ||
); | ||
|
||
return ( | ||
<TouchableWithoutFeedback onPress={this.handleClick}> | ||
<View style={[styles.agreeItem, style]}> | ||
<Checkbox | ||
ref={refCheckbox} | ||
style={[styles.agreeItemCheckbox, checkboxStyle]} | ||
disabled={disabled} | ||
checked={checked} | ||
defaultChecked={defaultChecked} | ||
onChange={onChange} | ||
/> | ||
<View style={{ flex: 1 }}>{contentDom}</View> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
<WithTheme styles={this.props.styles} themeStyles={AgreeItemstyles}> | ||
{styles => { | ||
const contentDom = !children ? null : React.isValidElement( | ||
children, | ||
) ? ( | ||
children | ||
) : ( | ||
<Text>{children}</Text> | ||
); | ||
|
||
return ( | ||
<TouchableWithoutFeedback onPress={this.handleClick}> | ||
<View style={[styles.agreeItem, style]}> | ||
<Checkbox | ||
ref={ref => (this.checkbox = ref)} | ||
style={[styles.agreeItemCheckbox, checkboxStyle]} | ||
disabled={disabled} | ||
checked={checked} | ||
defaultChecked={defaultChecked} | ||
onChange={onChange} | ||
/> | ||
<View style={{ flex: 1 }}>{contentDom}</View> | ||
</View> | ||
</TouchableWithoutFeedback> | ||
); | ||
}} | ||
</WithTheme> | ||
); | ||
} | ||
} |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.