• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the 'License');
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16if (!('finalizeConstruction' in ViewPU.prototype)) {
17    Reflect.set(ViewPU.prototype, 'finalizeConstruction', () => {
18    });
19}
20const LengthMetrics = requireNapi('arkui.node').LengthMetrics;
21
22const o19 = 4;
23const p19 = 8;
24const q19 = 24;
25const r19 = 48;
26const s19 = 48;
27
28export class SplitLayout extends ViewPU {
29    constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) {
30        super(parent, __localStorage, elmtId, extraInfo);
31        if (typeof paramsLambda === 'function') {
32            this.paramsGenerator_ = paramsLambda;
33        }
34        this.container = undefined;
35        this.__sizeValue = new ObservedPropertySimplePU('', this, 'sizeValue');
36        this.__areaWidth = new ObservedPropertySimplePU(0, this, 'areaWidth');
37        this.__imageBackgroundColor = new ObservedPropertySimplePU('#19000000', this, 'imageBackgroundColor');
38        this.__mainImage = new ObservedPropertyObjectPU(undefined, this, 'mainImage');
39        this.__primaryText = new SynchedPropertySimpleOneWayPU(params.primaryText, this, 'primaryText');
40        this.secondaryText = '';
41        this.tertiaryText = '';
42        this.setInitiallyProvidedValue(params);
43        this.finalizeConstruction();
44    }
45
46    setInitiallyProvidedValue(params) {
47        if (params.container !== undefined) {
48            this.container = params.container;
49        }
50        if (params.sizeValue !== undefined) {
51            this.sizeValue = params.sizeValue;
52        }
53        if (params.areaWidth !== undefined) {
54            this.areaWidth = params.areaWidth;
55        }
56        if (params.imageBackgroundColor !== undefined) {
57            this.imageBackgroundColor = params.imageBackgroundColor;
58        }
59        if (params.mainImage !== undefined) {
60            this.mainImage = params.mainImage;
61        }
62        if (params.primaryText === undefined) {
63            this.__primaryText.set('');
64        }
65        if (params.secondaryText !== undefined) {
66            this.secondaryText = params.secondaryText;
67        }
68        if (params.tertiaryText !== undefined) {
69            this.tertiaryText = params.tertiaryText;
70        }
71    }
72
73    updateStateVars(params) {
74        this.__primaryText.reset(params.primaryText);
75    }
76
77    purgeVariableDependenciesOnElmtId(rmElmtId) {
78        this.__sizeValue.purgeDependencyOnElmtId(rmElmtId);
79        this.__areaWidth.purgeDependencyOnElmtId(rmElmtId);
80        this.__imageBackgroundColor.purgeDependencyOnElmtId(rmElmtId);
81        this.__mainImage.purgeDependencyOnElmtId(rmElmtId);
82        this.__primaryText.purgeDependencyOnElmtId(rmElmtId);
83    }
84
85    aboutToBeDeleted() {
86        this.__sizeValue.aboutToBeDeleted();
87        this.__areaWidth.aboutToBeDeleted();
88        this.__imageBackgroundColor.aboutToBeDeleted();
89        this.__mainImage.aboutToBeDeleted();
90        this.__primaryText.aboutToBeDeleted();
91        SubscriberManager.Get().delete(this.id__());
92        this.aboutToBeDeletedInternal();
93    }
94
95    get sizeValue() {
96        return this.__sizeValue.get();
97    }
98
99    set sizeValue(newValue) {
100        this.__sizeValue.set(newValue);
101    }
102
103    get areaWidth() {
104        return this.__areaWidth.get();
105    }
106
107    set areaWidth(newValue) {
108        this.__areaWidth.set(newValue);
109    }
110
111    get imageBackgroundColor() {
112        return this.__imageBackgroundColor.get();
113    }
114
115    set imageBackgroundColor(newValue) {
116        this.__imageBackgroundColor.set(newValue);
117    }
118
119    get mainImage() {
120        return this.__mainImage.get();
121    }
122
123    set mainImage(newValue) {
124        this.__mainImage.set(newValue);
125    }
126
127    get primaryText() {
128        return this.__primaryText.get();
129    }
130
131    set primaryText(newValue) {
132        this.__primaryText.set(newValue);
133    }
134
135    initialRender() {
136        this.observeComponentCreation2((elmtId, isInitialRender) => {
137            Column.create();
138            Column.onAreaChange((oldValue, newValue) => {
139                console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`);
140                this.sizeValue = JSON.stringify(newValue);
141                this.areaWidth = parseInt(newValue.width.toString(), 0);
142                console.info(`pingAce: on area change, oldValue is` + this.areaWidth);
143                console.info(`pingAce: on area change, oldValue is` + parseInt(newValue.height.toString(), 0));
144            });
145        }, Column);
146        this.observeComponentCreation2((elmtId, isInitialRender) => {
147            If.create();
148            if (this.areaWidth <= 600) {
149                this.ifElseBranchUpdateFunction(0, () => {
150                    this.observeComponentCreation2((elmtId, isInitialRender) => {
151                        GridRow.create({
152                            columns: 4,
153                            breakpoints: {
154                                reference: BreakpointsReference.WindowSize
155                            },
156                            direction: GridRowDirection.Row
157                        });
158                    }, GridRow);
159                    this.observeComponentCreation2((elmtId, isInitialRender) => {
160                        GridCol.create({
161                            span: {
162                                xs: 4,
163                                sm: 4,
164                                md: 4,
165                                lg: 4
166                            }
167                        });
168                    }, GridCol);
169                    this.observeComponentCreation2((elmtId, isInitialRender) => {
170                        Column.create();
171                    }, Column);
172                    this.observeComponentCreation2((elmtId, isInitialRender) => {
173                        Stack.create({ alignContent: Alignment.Bottom });
174                        Stack.height('34%');
175                        Stack.width('100%');
176                    }, Stack);
177                    this.observeComponentCreation2((elmtId, isInitialRender) => {
178                        Image.create(this.mainImage);
179                        Image.height('100%');
180                        Image.width('100%');
181                    }, Image);
182                    this.observeComponentCreation2((elmtId, isInitialRender) => {
183                        Scroll.create();
184                        Scroll.scrollBar(BarState.On);
185                        Scroll.nestedScroll({
186                            scrollForward: NestedScrollMode.SELF_FIRST,
187                            scrollBackward: NestedScrollMode.SELF_FIRST,
188                        });
189                    }, Scroll);
190                    this.observeComponentCreation2((elmtId, isInitialRender) => {
191                        Column.create();
192                        Column.alignItems(HorizontalAlign.Center);
193                        Column.margin({
194                            left: {
195                                'id': -1,
196                                'type': 10002,
197                                params: ['sys.float.ohos_id_max_padding_start'],
198                                'bundleName': '__harDefaultBundleName__',
199                                'moduleName': '__harDefaultModuleName__'
200                            },
201                            right: {
202                                'id': -1,
203                                'type': 10002,
204                                params: ['sys.float.ohos_id_max_padding_end'],
205                                'bundleName': '__harDefaultBundleName__',
206                                'moduleName': '__harDefaultModuleName__'
207                            },
208                        });
209                    }, Column);
210                    this.observeComponentCreation2((elmtId, isInitialRender) => {
211                        Text.create(this.primaryText);
212                        Text.fontWeight(FontWeight.Medium);
213                        Text.textAlign(TextAlign.Center);
214                        Text.fontSize({
215                            'id': -1,
216                            'type': 10002,
217                            params: ['sys.float.Title_M'],
218                            'bundleName': '__harDefaultBundleName__',
219                            'moduleName': '__harDefaultModuleName__'
220                        });
221                        Text.fontColor({
222                            'id': -1,
223                            'type': 10001,
224                            params: ['sys.color.ohos_id_color_text_primary'],
225                            'bundleName': '__harDefaultBundleName__',
226                            'moduleName': '__harDefaultModuleName__'
227                        });
228                    }, Text);
229                    Text.pop();
230                    this.observeComponentCreation2((elmtId, isInitialRender) => {
231                        Text.create(this.secondaryText);
232                        Text.textAlign(TextAlign.Center);
233                        Text.fontSize({
234                            'id': -1,
235                            'type': 10002,
236                            params: ['sys.float.Body_M'],
237                            'bundleName': '__harDefaultBundleName__',
238                            'moduleName': '__harDefaultModuleName__'
239                        });
240                        Text.fontColor({
241                            'id': -1,
242                            'type': 10001,
243                            params: ['sys.color.ohos_id_color_text_primary'],
244                            'bundleName': '__harDefaultBundleName__',
245                            'moduleName': '__harDefaultModuleName__'
246                        });
247                        Text.margin({ top: o19, bottom: p19 });
248                    }, Text);
249                    Text.pop();
250                    this.observeComponentCreation2((elmtId, isInitialRender) => {
251                        Text.create(this.tertiaryText);
252                        Text.textAlign(TextAlign.Center);
253                        Text.fontSize({
254                            'id': -1,
255                            'type': 10002,
256                            params: ['sys.float.Caption_M'],
257                            'bundleName': '__harDefaultBundleName__',
258                            'moduleName': '__harDefaultModuleName__'
259                        });
260                        Text.fontColor({
261                            'id': -1,
262                            'type': 10001,
263                            params: ['sys.color.ohos_id_color_text_secondary'],
264                            'bundleName': '__harDefaultBundleName__',
265                            'moduleName': '__harDefaultModuleName__'
266                        });
267                        Text.margin({ bottom: q19 });
268                    }, Text);
269                    Text.pop();
270                    Column.pop();
271                    Scroll.pop();
272                    Stack.pop();
273                    this.observeComponentCreation2((elmtId, isInitialRender) => {
274                        Column.create();
275                        Column.height('66%');
276                        Column.width('100%');
277                    }, Column);
278                    this.container.bind(this)();
279                    Column.pop();
280                    Column.pop();
281                    GridCol.pop();
282                    GridRow.pop();
283                });
284            } else if (600 < this.areaWidth && this.areaWidth <= 840) {
285                this.ifElseBranchUpdateFunction(1, () => {
286                    this.observeComponentCreation2((elmtId, isInitialRender) => {
287                        GridRow.create({
288                            columns: 8,
289                            breakpoints: {
290                                reference: BreakpointsReference.WindowSize
291                            },
292                            direction: GridRowDirection.Row
293                        });
294                    }, GridRow);
295                    this.observeComponentCreation2((elmtId, isInitialRender) => {
296                        GridCol.create({
297                            span: {
298                                xs: 8,
299                                sm: 8,
300                                md: 8,
301                                lg: 8
302                            }
303                        });
304                    }, GridCol);
305                    this.observeComponentCreation2((elmtId, isInitialRender) => {
306                        Column.create();
307                    }, Column);
308                    this.observeComponentCreation2((elmtId, isInitialRender) => {
309                        Row.create();
310                        Row.backgroundColor(this.imageBackgroundColor);
311                        Row.height('34%');
312                        Row.width('100%');
313                    }, Row);
314                    this.observeComponentCreation2((elmtId, isInitialRender) => {
315                        Image.create(this.mainImage);
316                        Image.margin({ start: LengthMetrics.vp(96), end: LengthMetrics.vp(36) });
317                        Image.height('60%');
318                        Image.width('20%');
319                    }, Image);
320                    this.observeComponentCreation2((elmtId, isInitialRender) => {
321                        Scroll.create();
322                        Scroll.scrollBar(BarState.On);
323                        Scroll.nestedScroll({
324                            scrollForward: NestedScrollMode.SELF_FIRST,
325                            scrollBackward: NestedScrollMode.SELF_FIRST,
326                        });
327                    }, Scroll);
328                    this.observeComponentCreation2((elmtId, isInitialRender) => {
329                        Column.create();
330                        Column.width('42%');
331                        Column.alignItems(HorizontalAlign.Start);
332                        Column.margin({ end: LengthMetrics.vp(96) });
333                    }, Column);
334                    this.observeComponentCreation2((elmtId, isInitialRender) => {
335                        Text.create(this.primaryText);
336                        Text.fontWeight(FontWeight.Medium);
337                        Text.fontSize({
338                            'id': -1,
339                            'type': 10002,
340                            params: ['sys.float.Title_M'],
341                            'bundleName': '__harDefaultBundleName__',
342                            'moduleName': '__harDefaultModuleName__'
343                        });
344                        Text.fontColor({
345                            'id': -1,
346                            'type': 10001,
347                            params: ['sys.color.ohos_id_color_text_primary'],
348                            'bundleName': '__harDefaultBundleName__',
349                            'moduleName': '__harDefaultModuleName__'
350                        });
351                    }, Text);
352                    Text.pop();
353                    this.observeComponentCreation2((elmtId, isInitialRender) => {
354                        Text.create(this.secondaryText);
355                        Text.fontSize({
356                            'id': -1,
357                            'type': 10002,
358                            params: ['sys.float.Body_M'],
359                            'bundleName': '__harDefaultBundleName__',
360                            'moduleName': '__harDefaultModuleName__'
361                        });
362                        Text.fontColor({
363                            'id': -1,
364                            'type': 10001,
365                            params: ['sys.color.ohos_id_color_text_primary'],
366                            'bundleName': '__harDefaultBundleName__',
367                            'moduleName': '__harDefaultModuleName__'
368                        });
369                        Text.margin({ top: o19, bottom: p19 });
370                    }, Text);
371                    Text.pop();
372                    this.observeComponentCreation2((elmtId, isInitialRender) => {
373                        Text.create(this.tertiaryText);
374                        Text.fontSize({
375                            'id': -1,
376                            'type': 10002,
377                            params: ['sys.float.Caption_M'],
378                            'bundleName': '__harDefaultBundleName__',
379                            'moduleName': '__harDefaultModuleName__'
380                        });
381                        Text.fontColor({
382                            'id': -1,
383                            'type': 10001,
384                            params: ['sys.color.ohos_id_color_text_secondary'],
385                            'bundleName': '__harDefaultBundleName__',
386                            'moduleName': '__harDefaultModuleName__'
387                        });
388                        Text.margin({ bottom: q19 });
389                    }, Text);
390                    Text.pop();
391                    Column.pop();
392                    Scroll.pop();
393                    Row.pop();
394                    this.observeComponentCreation2((elmtId, isInitialRender) => {
395                        Column.create();
396                        Column.width('100%');
397                        Column.height('66%');
398                    }, Column);
399                    this.container.bind(this)();
400                    Column.pop();
401                    Column.pop();
402                    GridCol.pop();
403                    GridRow.pop();
404                });
405            } else if (this.areaWidth > 840) {
406                this.ifElseBranchUpdateFunction(2, () => {
407                    this.observeComponentCreation2((elmtId, isInitialRender) => {
408                        GridRow.create({
409                            columns: 12,
410                            breakpoints: {
411                                reference: BreakpointsReference.WindowSize
412                            },
413                            direction: GridRowDirection.Row
414                        });
415                        GridRow.width('100%');
416                    }, GridRow);
417                    this.observeComponentCreation2((elmtId, isInitialRender) => {
418                        GridCol.create({
419                            span: {
420                                xs: 4,
421                                sm: 4,
422                                md: 4,
423                                lg: 4
424                            }
425                        });
426                        GridCol.height('100%');
427                    }, GridCol);
428                    this.observeComponentCreation2((elmtId, isInitialRender) => {
429                        Flex.create({
430                            justifyContent: FlexAlign.Center,
431                            alignItems: ItemAlign.Center,
432                            direction: FlexDirection.Column
433                        });
434                        Flex.width('100%');
435                        Flex.height('100%');
436                        Flex.backgroundColor(this.imageBackgroundColor);
437                    }, Flex);
438                    this.observeComponentCreation2((elmtId, isInitialRender) => {
439                        Image.create(this.mainImage);
440                        Image.height('17%');
441                        Image.width('34%');
442                        Image.margin({ bottom: 36 });
443                    }, Image);
444                    this.observeComponentCreation2((elmtId, isInitialRender) => {
445                        Scroll.create();
446                        Scroll.scrollBar(BarState.On);
447                        Scroll.nestedScroll({
448                            scrollForward: NestedScrollMode.SELF_FIRST,
449                            scrollBackward: NestedScrollMode.SELF_FIRST,
450                        });
451                    }, Scroll);
452                    this.observeComponentCreation2((elmtId, isInitialRender) => {
453                        Column.create();
454                        Column.alignItems(HorizontalAlign.Center);
455                        Column.margin({
456                            left: {
457                                'id': -1,
458                                'type': 10002,
459                                params: ['sys.float.ohos_id_max_padding_start'],
460                                'bundleName': '__harDefaultBundleName__',
461                                'moduleName': '__harDefaultModuleName__'
462                            },
463                            right: {
464                                'id': -1,
465                                'type': 10002,
466                                params: ['sys.float.ohos_id_max_padding_end'],
467                                'bundleName': '__harDefaultBundleName__',
468                                'moduleName': '__harDefaultModuleName__'
469                            },
470                        });
471                    }, Column);
472                    this.observeComponentCreation2((elmtId, isInitialRender) => {
473                        Text.create(this.primaryText);
474                        Text.textAlign(TextAlign.Center);
475                        Text.fontWeight(FontWeight.Medium);
476                        Text.fontSize({
477                            'id': -1,
478                            'type': 10002,
479                            params: ['sys.float.Title_M'],
480                            'bundleName': '__harDefaultBundleName__',
481                            'moduleName': '__harDefaultModuleName__'
482                        });
483                        Text.fontColor({
484                            'id': -1,
485                            'type': 10001,
486                            params: ['sys.color.ohos_id_color_text_primary'],
487                            'bundleName': '__harDefaultBundleName__',
488                            'moduleName': '__harDefaultModuleName__'
489                        });
490                        Text.margin({ left: r19, right: s19 });
491                    }, Text);
492                    Text.pop();
493                    this.observeComponentCreation2((elmtId, isInitialRender) => {
494                        Text.create(this.secondaryText);
495                        Text.textAlign(TextAlign.Center);
496                        Text.fontSize({
497                            'id': -1,
498                            'type': 10002,
499                            params: ['sys.float.Body_M'],
500                            'bundleName': '__harDefaultBundleName__',
501                            'moduleName': '__harDefaultModuleName__'
502                        });
503                        Text.fontColor({
504                            'id': -1,
505                            'type': 10001,
506                            params: ['sys.color.ohos_id_color_text_primary'],
507                            'bundleName': '__harDefaultBundleName__',
508                            'moduleName': '__harDefaultModuleName__'
509                        });
510                        Text.margin({
511                            top: o19,
512                            bottom: p19,
513                            left: r19,
514                            right: s19
515                        });
516                    }, Text);
517                    Text.pop();
518                    this.observeComponentCreation2((elmtId, isInitialRender) => {
519                        Text.create(this.tertiaryText);
520                        Text.textAlign(TextAlign.Center);
521                        Text.fontSize({
522                            'id': -1,
523                            'type': 10002,
524                            params: ['sys.float.Caption_M'],
525                            'bundleName': '__harDefaultBundleName__',
526                            'moduleName': '__harDefaultModuleName__'
527                        });
528                        Text.fontColor({
529                            'id': -1,
530                            'type': 10001,
531                            params: ['sys.color.ohos_id_color_text_secondary'],
532                            'bundleName': '__harDefaultBundleName__',
533                            'moduleName': '__harDefaultModuleName__'
534                        });
535                        Text.margin({ left: r19, right: s19, bottom: q19 });
536                    }, Text);
537                    Text.pop();
538                    Column.pop();
539                    Scroll.pop();
540                    Flex.pop();
541                    GridCol.pop();
542                    this.observeComponentCreation2((elmtId, isInitialRender) => {
543                        GridCol.create({
544                            span: {
545                                xs: 8,
546                                sm: 8,
547                                md: 8,
548                                lg: 8
549                            }
550                        });
551                    }, GridCol);
552                    this.container.bind(this)();
553                    GridCol.pop();
554                    GridRow.pop();
555                });
556            } else {
557                this.ifElseBranchUpdateFunction(3, () => {
558                });
559            }
560        }, If);
561        If.pop();
562        Column.pop();
563    }
564
565    rerender() {
566        this.updateDirtyElements();
567    }
568}
569
570export default { SplitLayout };