使用XML描述的Flexbox布局的UI开发框架。
元素解析XML所描述的节点,包括:
<Box>容器<View>视图<Text>文本
Node是布局节点,Flexbox计算Node Tree的布局关系,得到所有Node的Frame,每个Node.frame中的位置值都是相对于其父节点的坐标系。 该框架提供了抽象的节点协议,当前采用Yoga实现Flexbox布局,如果有需要,可以用其它库实现Flexbox布局。
组件实现元素所描述的能力:
- Box组件实现
<Box>元素,管理了一个Node节点对象,并提供了组件在布局过程中所需的抽象方法,是所有参与布局的组件的基类;但由于Box组件是一种虚拟视图,不会真实显示出来,所以只是作为组件的容器为子组件提供空间坐标系; - View组件实现
<View>元素,继承自Box组件,并管理了一个Native视图对象,作为真实视图,其View.frame的位置是相对于父视图SuperView的空间坐标系; - Text组件实现
<Text>元素,继承自View组件,管理的Native视图对象提供文本显示的能力,可配置文本的字体、颜色、阴影等;
元素的key属性是可选常量,如果未提供会自动生成默认值,将据此实现组件和重用能力。
<View key="container">
;表达多个样式:表达键值对,表示一个值由多个部分构成,即数据结构的概念|表示多个值,即数组的概念
<View style="paddingHorizontal:16; backgroundColor:255,0,255; touchableOpacity">
<LinearGradient style="positionType:absolute; position:0; startPoint:0,0; endPoint:0,1; locations:0|1; colors:white|#00FFFF,0.7"/>
</View>
元素的style属性是组合格式的字符串,解析后的样式字典可为组件所用。
- 变量可用于元素的除
key之外的所有属性值 - 使用
{变量名}来描述变量名,通常用路径表示法,如:{user/name} - 组件渲染过程中,在将元素样式字符串转换为组件样式字典的时候会从
Canvas获取所有变量的值
- 事件通过元素的属性表达
- 使用
on前缀描述事件,如:onPress - 使用字符串描述消息,通常用路径表示法,可带变量参数,如:onPress=“alert?message=欢迎{user/name}”同学
- 当事件触发时,将会向
Canvas发送事件及消息
direction书写方向,枚举值:inherit, ltr, rtlflexDirection主轴方向,枚举值:column, columnReverse, row, rowReversejustifyContent主轴内容默认对齐方式,枚举值:flexStart, center, flexEnd, spaceBetween, spaceAround, spaceEvenlyalignItems副轴内容默认对齐方式,align枚举值:auto, flexStart, center, flexEnd, stretch, baseline, spaceBetween, spaceAroundalignContent,副轴内容多行时,这些行的对齐方式,参考align枚举值alignSelf重载自身在其父元素中沿副轴的对齐方式,参考align枚举值positionType位置类型,枚举值:relative, absoluteflexWrap伸缩换行,枚举值:noWrap, wrap, wrapReverseoverflow溢出部分如何显示,枚举值:visible, hiddenflexflexGrowflexShrinkflexBasismarginmarginHorizontalmarginVerticalmarginStartmarginEndmarginLeftmarginTopmarginRightmarginBottompositionpositionHorizontalpositionVerticalpositionLeftpositionToppositionRightpositionBottompaddingpaddingHorizontalpaddingVerticalpaddingStartpaddingEndpaddingLeftpaddingToppaddingRightpaddingBottomborderborderHorizontalborderVerticalborderStartborderEndborderLeftborderTopborderRightborderBottomsizewidthheightminSizeminWidthminHeightmaxSizemaxWidthmaxHeightaspectRatio宽高比,比例或浮点数,如 3:2 或 1.5
- 继承自Box Style
opacity透明度,0 ~ 1的浮点数overflow参考Box Style中的overflow,如果'hidden'则超出当前视图区域之外的内容将不被显示backgroundColor背景色,颜色borderColor边框色,颜色- 四边的厚度取决于Box Style中的
border及各种border*属性 borderRadius边框圆角,浮点数borderCorners边框圆角,数组:all, topLeft, topRight, bottomLeft, bottomRight, top, bottom, left, right,默认allshadowColor阴影颜色shadowOffset阴影偏移shadowOpacity阴影透明度shadowRadius阴影半径,羽化范围
nativeView自定义视图对象的标识名touchableOpacity触摸时是否有透明效果
onRef引用事件,当视图对象加入画布时触发,客户端持有引用视图时请注意使用weak声明onPress点击事件onLongPress长按事件
- 继承自View Style
fontSize字体大小,默认14fontName字体名fontStyle字体样式,枚举值:"normal", "italic", "bold"fontWeight字体粗细,整数值:0(默认), 100, 200, 300, 400, 500, 600, 700, 800, 900textColor字体颜色,默认黑色textAlign字体水平对其方式,枚举值:"left", "center", "right", "justify", "auto"lineBreak断行模式,枚举值:"wordWrapping", "charWrapping", "clipping", "truncatingHead", "truncatingTail", "truncatingMiddle"textShadowColor文本阴影颜色textShadowOffset文本阴影偏移textShadowRadius文本阴影模糊半径(羽化半径)numberOfLines文本最大行数,整数:0(无限制), 1, 2, 3, ...
text文本内容
- 继承自View Style
tintColor着色,将图像的非透明区域设置为统一的颜色contentMode内容模式,枚举值:"stretch", "contain", "cover", "repeat", "center", "top", "bottom", "left", "right", "topLeft", "topRight", "bottomLeft", "bottomRight"
uri图像地址
- 继承自View Style
onScroll滚动事件
FlexboxCanvas is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'FlexboxCanvas'FCCanvasView *canvas = [[FCCanvasView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:canvas];
[canvas loadXMLResource:@"test.xml" inBundle:nil];
mymong, mymong@163.com
FlexboxCanvas is available under the MIT license. See the LICENSE file for more info.

