Replies: 1 comment
-
Alternative Proposal: Direct Usage of Vue Syntax for CompilationProposalInstead of creating a new AST transformation pipeline, we can leverage Vue's existing compiler and syntax directly to generate SwiftUI and Jetpack Compose code. This approach offers the following advantages:
Implementation Overview
Input Template (Vue)<template>
<div>
<h1>{{ title }}</h1>
<p v-if="showText">{{ text }}</p>
<ul>
<li v-for="item in items" :key="item">{{ item }}</li>
</ul>
</div>
</template>
<script>
import { ref } from 'vue';
export default {
setup() {
const title = ref('Hello, World!');
const showText = ref(true);
const text = ref('This is a conditional text.');
const items = ref(['Item 1', 'Item 2', 'Item 3']);
return {
title,
showText,
text,
items,
};
},
};
</script>
|
Beta Was this translation helpful? Give feedback.
-
Technical Proposal: Cross-Platform View Layer Reuse Based on Template Separation
Background and Requirements
Challenges in View Reuse
Cross-platform development (e.g., iOS and Android) often requires platform-specific view code, which significantly increases development and maintenance costs.
Mature Logic Sharing Solutions
Frameworks like KMM (Kotlin Multiplatform Mobile) have improved efficiency by sharing logic layers, but there is still substantial room for improvement in view layer reuse.
Separation of View and Logic
Inspired by Vue's Single-File Component (SFC) structure, this proposal suggests reusing the
template
andstyle
parts for cross-platform views while retaining thescript
part for native code (e.g., Swift and Kotlin). This approach reduces view code duplication and enhances flexibility by combining shared views with native logic.Technical Path
1. Template-Driven View Layer
Concept
Use a Vue-like
template
to define the view structure. The HTML-style syntax is intuitive and easy to understand.template
into platform-specific view code:View
structures for iOS.Composable
structures for Android.Implementation
A template compiler parses the
template
into an abstract syntax tree (AST) and generates corresponding platform code.2. Style-Driven Visual Consistency
Concept
Use CSS-like
style
syntax to describe view styles..foregroundColor
,.font
).Modifier
).Implementation
A style compiler maps shared style rules to platform-specific implementations.
3. Flexible Native Logic Integration
Concept
script
section, maintaining seamless integration with platform-specific logic.Implementation
The
script
section is directly embedded in the target platform logic without additional compilation.Advantages of .vue Over JSX
Compared to JSX, Vue's SFC model offers several advantages:
Clear Separation of Concerns
template
,style
, andscript
into distinct sections, making it easier to organize and maintain.Better Compilation Suitability
Stronger Extensibility
v-if
,v-for
) that can be optimized during compilation for efficient rendering.Framework Implementation Overview
1. Architecture Design
Each component is written in a
.dioxus
file (or similar extension), mimicking Vue's SFC:2. Compilation Workflow
Template Compilation
Parse the
template
into an AST and map it to platform-specific view code:SwiftUI example:
Jetpack Compose example:
Style Compilation
Convert the
style
section into platform-specific style declarations.Script Integration
Embed the
script
section directly into the target platform logic.Beta Was this translation helpful? Give feedback.
All reactions