#builderpage
Explore tagged Tumblr posts
harmonyos-next · 3 months ago
Text
How to use HarmonyOS NEXT - @Builder Custom Build Function?
note:Before reading this document, it is recommended to read: Basic Grammar Overview, Declarative UI Description, Custom Components - Create Custom Components.
ArkUI provides a lightweight UI element reuse mechanism @Builder, which has a fixed internal UI structure and only transfers data with the user. Developers can abstract reused UI elements into a method and call it in the build method.
It can be understood as a reusable set of components
Decorator usage instructions There are two ways to use the @Builder decorator, which are private custom build functions defined within custom components and global custom build functions defined globally.
definition: [code] @Builder MyBuilderFunction() {} [/code] use [code] this.MyBuilderFunction() [/code]
Private custom build function [code] @Entry @Component struct BuilderDemo { @Builder showTextBuilder() { Text('Hello World') .fontSize(30) .fontWeight(FontWeight.Bold) } @Builder showTextValueBuilder(param: string) { Text(param) .fontSize(30) .fontWeight(FontWeight.Bold) } build() { Column() { // No parameters this.showTextBuilder() // There are parameters this.showTextValueBuilder('Hello @Builder') } } } [/code] ·Allow the definition of one or more @ Builder methods within a custom component, which are considered private, special type member functions of the component. ·Private user-defined building functions can be called in user-defined components, build methods and other user-defined building functions. ·In a custom function body, 'this' refers to the current component to which it belongs, and the component's state variables can be accessed within the custom build function. Suggest accessing the state variables of custom components through this instead of passing parameters.
Global custom build function [code] @Builder function showTextBuilder() { Text('Hello World. This is builded by @Builder') .fontSize(30) .fontWeight(FontWeight.Bold) } @Entry @Component struct BuilderDemo { build() { Column() { showTextBuilder() } } } [/code] ·If there are no component state changes involved, it is recommended to use a global custom build method. ·Global user-defined building functions can be called in the build method and other user-defined building functions.
Code Example: BuilderPage [code] @Entry @Component struct BuilderPage { @State message: string = '@Builder custom build function';
@Builder task(taskName:string,state:boolean){ Row(){ Text(taskName) Blank() Text(state?'已完成':'未完成').fontColor(state?Color.Green:Color.Red) }.width('100%').padding(10).borderWidth({bottom:1}) }
build() { Column() { Text(this.message) .fontSize(20) .fontWeight(FontWeight.Bold) Text('任务清单') .width('100%') .backgroundColor('#EEEEEE') .fontWeight(FontWeight.Bold) .textAlign(TextAlign.Center) .padding(10) .borderWidth({bottom:1}) Row(){ Text('晨跑') Blank() Text('已完成').fontColor(Color.Green) }.width('100%').padding(10).borderWidth({bottom:1}) Row(){ Text('早读') Blank() Text('未完成').fontColor(Color.Red) }.width('100%').padding(10).borderWidth({bottom:1}) this.task('默写',true) this.task('练习书法',false) } .height('100%') .width('100%')
} } [/code]
parameter passing rule There are two types of parameter passing for custom build functions: value passing and reference passing, both of which must follow the following rules: ·The type of the parameter must be consistent with the declared type of the parameter, and expressions that return undefined or null are not allowed. ·Within functions decorated with @ Builder, it is not allowed to change parameter values. ·The UI syntax in @ Builder follows the rules of UI syntax. ·Only when a parameter is passed in, and the parameter needs to be passed directly to the object literal, will it be passed by reference. All other passing methods are passed by value.
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Finished building my exia darkmatter. Now to deconstruct and repaint it. . . . #gunplapage #gundam #gundamexia #gundamexiadarkmatter #exia #exiadarkmatter #darkmatter #darkmatterbooster #finished #paintjob #paint #purple #blue #red #silver #custompaintjob #deconstruction #modelbuilderpage #builderpage #builderlife
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Finished the booster foto my exia. . . . #exiadarkmatter #darkmatterbooster #booster #gunplapage #gunpla #gundam #gundamexiadarkmatter #bandai #jetpack #modelbuilderpage #imgunplabuilder #imagunplabuilder #builderpage #bird #red #black #hobby
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Progress. . . #exia #exiadarkmatter #mastergrade #mg #gundam #gunpla #bandai #bandaikit #imagunplabuilder #gunplapage #modelbuilder #wip #workinprogress #builderpage #modelbuilderpage #red #black
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Up next is Gundam exia dark matter ppgn-001 master grade. #exia #exiadarkmatter #mastergrade #mg #gundam #gunpla #bandai #bandaikit #imagunplabuilder #gunplapage #modelbuilder #wip #workinprogress #builderpage #modelbuilderpage #red #black
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Factory fresh C-3PO. Will weather tomorrow. #factoryfresh #c3po #protocoldroid #protocol #droid #droids #gunpla #gunplapage #starwars #starwarsmodel #starwarsminiature #starwarsbandai #bandaimodel #bandaikit #imagunplabuilder #builderpage #builder #modelbuilderpage #modelkit #modelbuilder
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Fooling around while building the Tie Fighter. #tiefighter #pilot #stormtrooper #starwars #newspaper #gunpla #bandai #bandaistarwarskits #gundam #imagunplabuilder #gunplapage #modelbuilderpage #builderpage #miniaturemodel #builderlife
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Progress first order tie fighter. #tiefighter #tiefighters #firstorder #spaceship #bandai #starwarsbandai #bandaistarwarskits #kit #starwars #theforceawakens #spaceshipmodel #starwarsmodel #modelbuilder #gunpla #imagunplabuilder #modelbuilderpage #builderpage #builderlife
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
I don't like throwing away boxes but I need the space for new sets 😅 #gunplapage #gupla #gundam #imagunplabuilder #dutch #gundamvidar #generalgrievous #r2d2 #bb8 #trash #box #unboxed #builderlife #builderpage #modelbuilder #modelbuilderpage
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Finished R4-P17! Had some great help from @r4_p17 thanks dude! #r4p17 #droid #starwars #starwarsmodel #miniaturemodel #bandaistarwars #starwarsbandai #modelbuilder #modelbuilderpage #builderpage #builderlife #bandai #gunpla #gundam
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
The Final steps. #r4p17 #droid #paint #paintjob #airbrush #gunpla #modelbuilderpage #builderpage #builderlife #bandaistarwars #starwars #starwarsbandai
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
The difference between weathering and factory fresh. #bb8 #starwarsmodel #starwars #theforceawakens #thelastjedi #starwarstheforceawakens #starwarsthelastjedi #droid #droids #sphere #spherical #droidmodel #gunpla #gundam #bandai #bandaistarwars #bandaimodel #bb8model #bb8starwars #modelbuilder #modelbuilderpage #builderlife #builderpage #weathering #weathered #panellining #machine #orange #white #lence #antenna #scale #1to12 #frame #body #steps
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Going to build this big set this week! Full mechanics Gundam Vidar. #builder #modelbuilder #gunpla #gundam #bandai #bandaimodel #builderlife #parts #firstpost #vero #dutch #follow #builderpage #modelbuilderpage #gundamvidar #vidar #fullmechanicsgundamvidar
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Finished some fighters for the panorama. . . #tiefighters #firstorder #fighters #xwing #panorama #battl #space #spaceship #spaceshipmodel #spacebattle #starwars #starwarsmodel #miniaturemodel #bandaimodel #bandaikit #bandai #gunplapage #gunpla #modelbuilderpage #builderpage #imagunplabuilder #modelbuilder
0 notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
Freshly painted! #darkmatter #darkmatterbooster #exiadarkmatter #exiadarkmattergundam #exiadarkmatterbooster #exia #gundam #gunpla #airbrush #custompaintjob #metallic #blue #red #silver #gunplapage #imgunplabuilder #imagunplabuilder #modelbuilderpage #builderpage #builderlife
2 notes · View notes
model-builder-mies-blog · 7 years ago
Photo
Tumblr media
X-wing down! Another one for the diorama. #xwing #starfighter #diorama #starwars #sw #spaceship #spaceshipmodel #battledamage #shot #imagunplabuilder #gunplapage #gunpla #bandai #bandaistarwars #modelbuilderpage #modelbuilder #builderpage #builder #builderlife
0 notes