หลักเกณฑ์เกี่ยวกับรูปแบบสำหรับ API ของ Jetpack Compose
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หากคุณเขียนโค้ด Compose สำหรับแอปหรือสร้างไลบรารีและ API ของ Compose โปรดทำตามแนวทางปฏิบัติแนะนำเพื่อให้โค้ดของคุณปรับขนาดได้ มีประสิทธิภาพมากขึ้น และสอดคล้องกับระบบนิเวศอื่นๆ
เอกสารต่อไปนี้มีหลักเกณฑ์สำหรับผู้ที่เขียนโค้ดที่ใช้ Compose
- หลักเกณฑ์ API สำหรับ Jetpack Compose: อธิบายรูปแบบ แนวทางปฏิบัติแนะนำ และหลักเกณฑ์ด้านสไตล์ที่กำหนดไว้สำหรับระบบที่ใช้ปลั๊กอินคอมไพเลอร์และรันไทม์ของ Jetpack Compose โดยมีหัวข้อต่อไปนี้
- หลักเกณฑ์การจัดรูปแบบ Kotlin สำหรับ Compose โดยอิงตามข้อกำหนดในการเขียนโค้ด Kotlin
- คำแนะนำสำหรับ
@Composable
ฟังก์ชันและ API ที่สร้างขึ้นจากความสามารถของรันไทม์ Compose
- หลักเกณฑ์สำหรับ API ที่ใช้และขยายชุดเครื่องมือ Compose UI
- รูปแบบการจัดการ Use Case เมื่อออกแบบ Compose API
- หลักเกณฑ์ API สำหรับคอมโพเนนต์
@Composable
ใน Jetpack Compose
มีชุดหลักเกณฑ์และคำแนะนำสำหรับการสร้างและใช้
@Composable
คอมโพเนนต์ UI รวมถึงหัวข้อต่อไปนี้
- การสร้างและวางเลเยอร์คอมโพเนนต์
- การตั้งชื่อคอมโพเนนต์ใหม่
- การแสดงทรัพยากร Dependency ของคอมโพเนนต์
- พารามิเตอร์ในคอมโพเนนต์
@Composable
- ทำตามรูปแบบที่ถูกต้องในการสร้างคลาสและฟังก์ชันที่เกี่ยวข้องกับคอมโพเนนต์
- การบันทึกคอมโพเนนต์
@Composable
- การปรับปรุงการช่วยเหลือพิเศษสำหรับคอมโพเนนต์
- การอัปเดต API ของคอมโพเนนต์ในขณะที่ยังคงความเข้ากันได้แบบย้อนหลัง
ผู้ชม
หลักเกณฑ์เหล่านี้เขียนขึ้นสำหรับกลุ่มเป้าหมาย 3 กลุ่มต่อไปนี้
- นักพัฒนาแอปที่สร้างแอปโดยอิงตาม Jetpack Compose คุณจะอยู่ในกลุ่มนี้
หากใช้ Jetpack Compose ในบางส่วนของแอป
- นักพัฒนาแอปที่ทำงานเกี่ยวกับการพัฒนาเฟรมเวิร์ก Jetpack Compose คุณจะอยู่ในกลุ่มนี้หากมีส่วนร่วมใน
androidx.compose
ไลบรารี
- นักพัฒนาแอปที่สร้างไลบรารีโดยอิงตาม Jetpack Compose คุณจะอยู่ในกลุ่มนี้หากสร้าง Compose API หรือไลบรารีขององค์ประกอบ UI ของ Compose ไลบรารีของคอมโพเนนต์ Compose เหล่านี้อาจพร้อมให้บริการแก่สาธารณะหรืออยู่ในบริษัทหรือทีมของคุณ
คุณจะมีระดับความเข้มงวดที่แตกต่างกันสำหรับหลักเกณฑ์ด้านสไตล์แต่ละข้อ ทั้งนี้ขึ้นอยู่กับกลุ่มที่คุณอยู่
ตัวอย่างเช่น โดยทั่วไปการพัฒนาเฟรมเวิร์ก Jetpack Compose จะ
ยึดมั่นในหลักเกณฑ์เหล่านี้อย่างเคร่งครัดที่สุด
ดูข้อมูลเพิ่มเติมเกี่ยวกับข้อกำหนดสำหรับกลุ่มเป้าหมายนักพัฒนาแอปแต่ละกลุ่มได้ที่
RFC2119
มีส่วนร่วมในกรอบและหลักเกณฑ์
เรายินดีรับการมีส่วนร่วมในไลบรารีที่เลือกในandroidx
โค้ดเบสและ
หลักเกณฑ์ด้านสไตล์ (หลักเกณฑ์ของ Compose API และ
หลักเกณฑ์ของคอมโพเนนต์ @Composable
)
หากต้องการร่วมให้ข้อมูล ให้ทำตามวิธีการในandroidx
คู่มือการร่วมให้ข้อมูล
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-04 UTC
[null,null,["อัปเดตล่าสุด 2025-09-04 UTC"],[],[],null,["If you're writing Compose code for your app or building Compose libraries and\nAPIs, follow best practices to make your code scalable, more performant, and\nconsistent with the rest of the ecosystem.\n\nThe following documents provide guidelines for anyone writing code that uses\nCompose:\n\n- [API Guidelines for Jetpack Compose](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-api-guidelines.md): Outlines patterns, best practices, and prescriptive style guidelines for any system using the Jetpack Compose compiler plugin and runtime. It includes the following topics:\n - Kotlin style guidelines for Compose, based on the [Kotlin Coding\n Conventions](https://kotlinlang.org/docs/coding-conventions.html)\n - Guidance for `@Composable` functions and APIs that build on the Compose runtime capabilities\n - Guidelines for APIs that use and extend the Compose UI toolkit\n - Patterns for addressing use cases when designing a Compose API\n- [API Guidelines for `@Composable` components in Jetpack Compose](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-component-api-guidelines.md): Provides a set of guidelines and recommendations for creating and using `@Composable` UI components, including the following topics:\n - Creating and layering components\n - Naming a new component\n - Expressing component dependencies\n - Parameters in `@Composable` components\n - Following correct patterns for creating component-related classes and functions\n - Documenting `@Composable` components\n - Improving accessibility for components\n - Updating component APIs while retaining backwards compatibility\n\nAudience\n\nThese guidelines are written for the following three audiences:\n\n- **Developers building apps based on Jetpack Compose**. You are in this group if you use Jetpack Compose in some part of your app.\n- **Developers working on Jetpack Compose framework development** . You are in this group if you make contributions to the [`androidx.compose` libraries](/jetpack/androidx/releases/compose).\n- **Developers creating libraries based on Jetpack Compose**. You are in this group if you create Compose APIs or libraries of Compose UI elements. These libraries of Compose components may be publicly available or local to your company or team.\n\nDepending on the group you're in, you have different strictness levels for each\nstyle guideline. For example, Jetpack Compose framework development generally\nadheres most strictly to these guidelines.\n\nFor more information about the requirements for each developer audience, see\n[RFC2119](https://www.ietf.org/rfc/rfc2119.txt).\n\nContribute to framework and guidelines\n\nWe welcome contributions to select libraries in the `androidx` codebase and the\nstyle guidelines ([Compose API guidelines](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-api-guidelines.md) and\n[`@Composable` components guidelines](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-component-api-guidelines.md)) themselves.\n\nTo contribute, follow the instructions in the `androidx` [contribution\nguide](https://android.googlesource.com/platform/frameworks/support/+/androidx-main/CONTRIBUTING.md)."]]