android: fix crash when parameter is null

This commit is contained in:
pengfei.zhou 2021-09-13 13:09:32 +08:00 committed by osborn
parent e6647214dd
commit f16648c3d1
2 changed files with 120 additions and 29 deletions

View File

@ -101,8 +101,12 @@ public class DoricNativeDriver implements IDoricDriver {
if (object == contextId) { if (object == contextId) {
continue; continue;
} }
if (object == null) {
stringBuilder.append("null").append(",");
} else {
stringBuilder.append(object.toString()).append(","); stringBuilder.append(object.toString()).append(",");
} }
}
final String anchorName = stringBuilder.toString(); final String anchorName = stringBuilder.toString();
final DoricPerformanceProfile finalProfile = profile; final DoricPerformanceProfile finalProfile = profile;
if (finalProfile != null) { if (finalProfile != null) {

View File

@ -1,51 +1,138 @@
import { import {
jsx, jsx,
VLayout, VLayout,
HLayout,
Panel, Panel,
Gravity, Gravity,
Group, Group,
layoutConfig, layoutConfig,
Text, Text,
createRef, createRef,
Color,
loge,
} from "doric"; } from "doric";
function createFragment() {
return (
<>
<Text text="This is line 1 in fragment"></Text>
<Text text="This is line 2 in fragment"></Text>
</>
);
}
@Entry @Entry
class Counter extends Panel { class Counter extends Panel {
build(root: Group) { build(root: Group) {
const fragments = createFragment(); root.backgroundColor = Color.BLACK;
const ref = createRef<Text>(); const hour1Ref = createRef<Text>();
let count = 0; const hour2Ref = createRef<Text>();
const min1Ref = createRef<Text>();
const min2Ref = createRef<Text>();
const sec1Ref = createRef<Text>();
const sec2Ref = createRef<Text>();
const comm1Ref = createRef<Text>();
const comm2Ref = createRef<Text>();
<VLayout <VLayout
space={20} space={20}
gravity={Gravity.Center} gravity={Gravity.Center}
layoutConfig={layoutConfig().fit().configAlignment(Gravity.Center)} layoutConfig={layoutConfig().fit().configAlignment(Gravity.Center)}
parent={root} parent={root}
> >
<Text textSize={40} ref={ref}> <HLayout space={5}>
{`${count}`} <Text
textSize={40}
ref={hour1Ref}
textColor={Color.WHITE}
border={{ width: 1, color: Color.BLUE }}
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
>
0
</Text> </Text>
<Text <Text
textSize={20} textSize={40}
text="Click to count" ref={hour2Ref}
onClick={() => { textColor={Color.WHITE}
count++; border={{ width: 1, color: Color.BLUE }}
ref.current.text = `${count}`; padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
}} >
></Text> 0
{fragments} </Text>
{fragments} <Text
{[0, 1, 2, 3].map((i) => ( ref={comm1Ref}
<Text text={`Index ${i}`} /> textColor={Color.WHITE}
))} textSize={40}
padding={{ top: 10, bottom: 10 }}
>
:
</Text>
<Text
textSize={40}
ref={min1Ref}
textColor={Color.WHITE}
border={{ width: 1, color: Color.BLUE }}
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
>
0
</Text>
<Text
textSize={40}
ref={min2Ref}
textColor={Color.WHITE}
border={{ width: 1, color: Color.BLUE }}
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
>
0
</Text>
<Text
ref={comm2Ref}
textSize={40}
textColor={Color.WHITE}
padding={{ top: 10, bottom: 10 }}
>
:
</Text>
<Text
textSize={40}
ref={sec1Ref}
textColor={Color.WHITE}
border={{ width: 1, color: Color.BLUE }}
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
>
0
</Text>
<Text
textSize={40}
ref={sec2Ref}
textColor={Color.WHITE}
border={{ width: 1, color: Color.BLUE }}
padding={{ left: 10, right: 10, top: 10, bottom: 10 }}
>
0
</Text>
</HLayout>
</VLayout>; </VLayout>;
this.addOnRenderFinishedCallback(async () => {
const width = await root.getWidth(this.context);
[
hour1Ref,
hour2Ref,
comm1Ref,
min1Ref,
min2Ref,
comm2Ref,
sec1Ref,
sec2Ref,
].forEach((e) => {
e.current.apply({
border: undefined,
textSize: width / 10,
});
});
});
setInterval(() => {
const time = new Date();
hour1Ref.current.text = `${Math.floor(time.getHours() / 10)}`;
hour2Ref.current.text = `${Math.floor(time.getHours() % 10)}`;
min1Ref.current.text = `${Math.floor(time.getMinutes() / 10)}`;
min2Ref.current.text = `${Math.floor(time.getMinutes() % 10)}`;
sec1Ref.current.text = `${Math.floor(time.getSeconds() / 10)}`;
sec2Ref.current.text = `${Math.floor(time.getSeconds() % 10)}`;
}, 100);
} }
} }