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

fix: 更新radioGroup的状态 #15343

Open
wants to merge 4 commits into
base: 3.x
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface RadioGroupState {
export interface RadioGroupProps extends FormItemProps, _RadioGroupProps {
children?: React.ReactNode;
style?: StyleProp<ViewStyle> | any;
checkedValue?: string;
onChange?: (evt: EventGroupOnChange) => void;
_onGroupDataInitial?: (value: any) => void;
}
17 changes: 15 additions & 2 deletions packages/taro-components-rn/src/components/RadioGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

class _RadioGroup extends React.Component<RadioGroupProps, RadioGroupState> {
static displayName = '_RadioGroup'
state: RadioGroupState = {
checkedValue: undefined

constructor(props: RadioGroupProps) {
super(props);

Check failure on line 19 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Extra semicolon

Check failure on line 19 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Extra semicolon

Check failure on line 19 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon

Check failure on line 19 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon
const {checkedValue} = props;

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

A space is required after '{'

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

A space is required before '}'

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Extra semicolon

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

A space is required after '{'

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

A space is required before '}'

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Extra semicolon

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

A space is required after '{'

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

A space is required before '}'

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

A space is required after '{'

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

A space is required before '}'

Check failure on line 20 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon
this.state = {
checkedValue
};

Check failure on line 23 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Extra semicolon

Check failure on line 23 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Extra semicolon

Check failure on line 23 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon

Check failure on line 23 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon
}

// eslint-disable-next-line default-param-last
Expand All @@ -30,6 +35,14 @@
})
}

componentDidUpdate (prevProps) {
// 检测 props 是否发生变化
if (this.props.checkedValue !== prevProps.checkedValue) {
// 执行相应的操作,比如更新组件状态
this.setState({ checkedValue: this.props.checkedValue });

Check failure on line 42 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Extra semicolon

Check failure on line 42 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Extra semicolon

Check failure on line 42 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon

Check failure on line 42 in packages/taro-components-rn/src/components/RadioGroup/index.tsx

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon
}
}

findAndAttachCb = (children: React.ReactNode): React.ReactNode => {
return React.Children.toArray(children).map((child: any) => {
if (!child.type) return child
Expand Down
Loading