洞察探索open banking最新技术如何推动跨平台小程序开发,引领数字化转型新趋势
1213
2022-11-05
Stylist是一个高度可扩展的平台,用于创建和维护应用程序的基本Android XML主题集
As Android apps grow, providing common styling across app themes becomes challenging. Typically, this results in copy-pasting style items across themes, monolithic themes, or complicated inheritance trees. Stylist is a highly-extensible platform for creating and maintaining an app’s base set of Android XML themes.
Overview
Stylist is a Gradle plugin written in Kotlin that generates a base set of Android XML themes. Stylist-generated themes are created using a stencil and trait system. Each theme is declared with a single stencil, which is comprised of sets of logically-grouped style items. All of this comes together to create an easily maintainable system of stencils and traits.
ThemeStencils: A 1:1 ratio of ThemeStencils to corresponding generated themes. Each ThemeStencil declares a theme name and parent theme plus any extra StyleItemGroups that should be included in addition to the globally applicable set.
StyleItemGroups: Each StyleItemGroup can be declared by multiple ThemeStencils and generate otherwise duplicated style items across all themes that include them. Common examples include default app colors, font sizes, and common dimension values. They are a logical groupings of custom theme attributes that get included in each theme that declares the group.
Usage
A simple ThemeStencilProvider that defines text sizes in Dark and Light themes would look like:
@AutoService(ThemeStencilProvider::class)class SampleThemeStencilProvider : ThemeStencilProvider { private val textSizes = StyleItemGroup( StyleItem("textSizeSmall", "12dp"), StyleItem("textSizeMedium","16dp"), StyleItem("textSizeLarge", "20dp") ) override fun stencils() = linkedSetOf( ThemeStencil("Theme.Sample.Dark", "Theme.AppCompat"), ThemeStencil("Theme.Sample.Light", "Theme.AppCompat.Light") ) override fun globalStyleItemGroups() = linkedSetOf( textSizes )}
Leaving you with a generated themes XML resource file like this:
This may look like a lot of boilerplate for simple style item shared by two themes, but it scales quite well when you want to have many custom color, dimension, and other style items on numerous app themes and custom theme attributes.
Download
classpath 'com.uber.stylist:stylist:0.0.2'
classpath 'com.uber.stylist:stylist-core:0.0.2'
classpath 'com.uber.stylist:stylist-api:0.0.2'
License
Copyright (C) 2018 Uber TechnologiesLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at http://apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~