support 427 for Radio.checked

Signed-off-by: houhaoyu <houhaoyu@huawei.com>
Change-Id: Ieec61b12c7cd9d805f3f9fdcf137f96bba69e0d6
This commit is contained in:
houhaoyu
2022-02-08 17:39:27 +08:00
parent 34911fa12d
commit 8feaab40c6
4 changed files with 29 additions and 8 deletions
+2
View File
@@ -189,6 +189,8 @@ export const VISUAL_STATE: string = 'visualState';
export const VIEW_STACK_PROCESSOR: string = 'ViewStackProcessor';
export const BIND_POPUP: string = 'bindPopup';
export const CHECKED: string = 'checked';
export const RADIO: string = 'Radio';
export const $$_VALUE: string = 'value';
export const $$_CHANGE_EVENT: string = 'changeEvent';
export const $$_THIS: string = '$$this';
+16 -5
View File
@@ -53,6 +53,8 @@ import {
$$_CHANGE_EVENT,
$$_THIS,
$$_NEW_VALUE,
CHECKED,
RADIO,
BUILDER_ATTR_NAME,
BUILDER_ATTR_BIND,
CUSTOM_DIALOG_CONTROLLER_BUILDER
@@ -753,12 +755,10 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any,
statements, log, false, true, false);
}
lastStatement.kind = true;
} else if (propName === BIND_POPUP && temp.arguments.length === 2 &&
temp.arguments[0].getText().match(/^\$\$(.|\n)+/)) {
} else if (!isStylesAttr && [BIND_POPUP, CHECKED].includes(propName) &&
temp.arguments.length && temp.arguments[0] && temp.arguments[0].getText().match(/^\$\$(.|\n)+/)) {
const argumentsArr: ts.Expression[] = [];
const varExp: ts.Expression = updateArgumentFor$$(temp.arguments[0]);
argumentsArr.push(generateObjectFor$$(varExp));
argumentsArr.push(temp.arguments[1]);
classifyArgumentsNum(temp.arguments, argumentsArr, propName, identifierNode);
statements.push(ts.factory.createExpressionStatement(
createFunction(identifierNode, node, argumentsArr)));
lastStatement.kind = true;
@@ -779,6 +779,17 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any,
}
}
function classifyArgumentsNum(args: any, argumentsArr: ts.Expression[], propName: string,
identifierNode: ts.Identifier): void {
if (propName === BIND_POPUP && args.length === 2) {
const varExp: ts.Expression = updateArgumentFor$$(args[0]);
argumentsArr.push(generateObjectFor$$(varExp), args[1]);
} else if (propName === CHECKED && args.length === 1 && identifierNode.getText() === RADIO) {
const varExp: ts.Expression = updateArgumentFor$$(args[0]);
argumentsArr.push(varExp, createArrowFunctionFor$$(varExp));
}
}
function traverseStylesAttr(node: ts.Node): ts.Node {
if (ts.isStringLiteral(node)) {
node = ts.factory.createStringLiteral(node.text);
+3 -3
View File
@@ -481,9 +481,9 @@ function createParamsInitBlock(express: string, statements: ts.Statement[],
express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined :
ts.factory.createIdentifier(CREATE_CONSTRUCTOR_PARAMS), undefined,
express === COMPONENT_CONSTRUCTOR_DELETE_PARAMS ? undefined :
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier(parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined),
undefined)], undefined, ts.factory.createBlock(statements, true));
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier(parentComponentName.getText() + INTERFACE_NAME_SUFFIX), undefined),
undefined)], undefined, ts.factory.createBlock(statements, true));
return methodDeclaration;
}
+8
View File
@@ -31,6 +31,8 @@ struct HomeComponent {
Text(this.value1)
Text(this.value2)
Text(this.value3)
Radio({value: "Radio", group: "1"})
.checked($$this.value4)
}
Row() {
Button() {
@@ -45,6 +47,8 @@ struct HomeComponent {
.fontSize(100)
.bindPopup($$value6.item1, {message: "This is $$ for Obj"})
Text(this.value3)
Radio({value: "Radio", group: "1"})
.checked($$value5[0])
}
.width(20)
}
@@ -91,6 +95,8 @@ class HomeComponent extends View {
Text.pop();
Text.create(this.value3);
Text.pop();
Radio.create({ value: "Radio", group: "1" });
Radio.checked(this.value4, newValue => { this.value4 = newValue; });
Row.pop();
Row.create();
Row.width(20);
@@ -109,6 +115,8 @@ class HomeComponent extends View {
Text.pop();
Text.create(this.value3);
Text.pop();
Radio.create({ value: "Radio", group: "1" });
Radio.checked(value5[0], newValue => { value5[0] = newValue; });
Row.pop();
Column.pop();
}