File tree Expand file tree Collapse file tree 9 files changed +155
-1
lines changed
recompose-ast/src/main/kotlin/recompose
main/kotlin/recompose/composer
test/kotlin/recompose/composer
main/kotlin/recompose/parser/xml
test/kotlin/recompose/parser
recompose-test/src/main/resources Expand file tree Collapse file tree 9 files changed +155
-1
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 Sebastian Kaspari
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package recompose.ast.viewgroup
18
+
19
+ import recompose.ast.ViewGroupNode
20
+ import recompose.ast.attributes.ViewAttributes
21
+ import recompose.ast.attributes.ViewGroupAttributes
22
+ import recompose.visitor.Visitor
23
+
24
+ /* *
25
+ * Data classs holding value of a parsed `FrameLayout`
26
+ *
27
+ * https://developer.android.com/reference/android/widget/FrameLayout
28
+ */
29
+ data class FrameLayoutNode (
30
+ override val viewGroup : ViewGroupAttributes ,
31
+ override val view : ViewAttributes ,
32
+ ) : ViewGroupNode {
33
+ override fun accept (visitor : Visitor ) = visitor.visitFrameLayout(this )
34
+ }
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import recompose.ast.view.TextViewNode
25
25
import recompose.ast.view.ViewNode
26
26
import recompose.ast.viewgroup.CardViewNode
27
27
import recompose.ast.viewgroup.ConstraintLayoutNode
28
+ import recompose.ast.viewgroup.FrameLayoutNode
28
29
import recompose.ast.viewgroup.LinearLayoutNode
29
30
import recompose.ast.viewgroup.UnknownNode
30
31
@@ -41,6 +42,7 @@ interface Visitor {
41
42
fun visitCardView (node : CardViewNode )
42
43
fun visitImageView (node : ImageViewNode )
43
44
fun visitLinearLayout (node : LinearLayoutNode )
45
+ fun visitFrameLayout (node : FrameLayoutNode )
44
46
fun visitCheckBox (node : CheckBoxNode )
45
47
fun visitConstraintLayout (node : ConstraintLayoutNode )
46
48
fun visitUnknown (node : UnknownNode )
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import recompose.ast.view.TextViewNode
26
26
import recompose.ast.view.ViewNode
27
27
import recompose.ast.viewgroup.CardViewNode
28
28
import recompose.ast.viewgroup.ConstraintLayoutNode
29
+ import recompose.ast.viewgroup.FrameLayoutNode
29
30
import recompose.ast.viewgroup.LinearLayoutNode
30
31
import recompose.ast.viewgroup.UnknownNode
31
32
import recompose.composer.ext.findChains
@@ -172,6 +173,13 @@ internal class ComposingVisitor : Visitor {
172
173
}
173
174
}
174
175
176
+ override fun visitFrameLayout (node : FrameLayoutNode ) {
177
+ val rowModifier = ModifierBuilder (node)
178
+ writer.writeCall(name = " Box" , parameters = listOf (rowModifier.toCallParameter())) {
179
+ node.viewGroup.children.forEach { it.accept(this @ComposingVisitor) }
180
+ }
181
+ }
182
+
175
183
override fun visitConstraintLayout (node : ConstraintLayoutNode ) {
176
184
val modifier = ModifierBuilder (node)
177
185
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import recompose.ast.values.InputType
22
22
import recompose.ast.values.Size
23
23
24
24
/* *
25
- * Sealed class for types of parameter values that a passed to a `Composable`.
25
+ * Sealed class for types of parameter values that are passed to a `Composable`.
26
26
*/
27
27
internal sealed class ParameterValue {
28
28
class RawValue (
Original file line number Diff line number Diff line change @@ -300,4 +300,19 @@ class ComposerTest {
300
300
""" .trimIndent()
301
301
)
302
302
}
303
+
304
+ @Test
305
+ fun `FrameLayout with TextView and Button` () {
306
+ assertComposing(
307
+ fileName = " framelayout-textview-button.xml" ,
308
+ """
309
+ Box(modifier = Modifier.fillMaxWidth().fillMaxHeight().padding(16.dp)) {
310
+ Text(text = "Center", fontSize = 20.sp, modifier = Modifier.fillMaxWidth().fillMaxHeight())
311
+ Button(onClick = {}, modifier = Modifier.fillMaxWidth()) {
312
+ Text(text = "Button", textAlign = TextAlign.Center)
313
+ }
314
+ }
315
+ """ .trimIndent()
316
+ )
317
+ }
303
318
}
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import recompose.parser.xml.view.imageView
34
34
import recompose.parser.xml.view.textView
35
35
import recompose.parser.xml.view.view
36
36
import recompose.parser.xml.viewgroup.constraintLayout
37
+ import recompose.parser.xml.viewgroup.frameLayout
37
38
import recompose.parser.xml.viewgroup.linearLayout
38
39
import recompose.parser.xml.viewgroup.unknown
39
40
@@ -46,6 +47,7 @@ internal fun XmlPullParser.node(): Node {
46
47
return when (name) {
47
48
// ViewGroupNode
48
49
" LinearLayout" -> linearLayout()
50
+ " FrameLayout" -> frameLayout()
49
51
50
52
// ViewNode
51
53
" View" -> view()
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 Sebastian Kaspari
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package recompose.parser.xml.viewgroup
18
+
19
+ import org.xmlpull.v1.XmlPullParser
20
+ import recompose.ast.viewgroup.FrameLayoutNode
21
+ import recompose.parser.xml.viewAttributes
22
+ import recompose.parser.xml.viewGroupAttributes
23
+
24
+ /* *
25
+ * Parses a `<FrameLayout> element.
26
+ *
27
+ * https://developer.android.com/reference/android/widget/FrameLayout
28
+ */
29
+ fun XmlPullParser.frameLayout (): FrameLayoutNode {
30
+ return FrameLayoutNode (
31
+ view = viewAttributes(),
32
+ viewGroup = viewGroupAttributes()
33
+ )
34
+ }
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import recompose.ast.view.TextViewNode
36
36
import recompose.ast.view.ViewNode
37
37
import recompose.ast.viewgroup.CardViewNode
38
38
import recompose.ast.viewgroup.ConstraintLayoutNode
39
+ import recompose.ast.viewgroup.FrameLayoutNode
39
40
import recompose.ast.viewgroup.LinearLayoutNode
40
41
import recompose.test.utils.assertAST
41
42
@@ -418,4 +419,42 @@ class ParserTest {
418
419
)
419
420
)
420
421
}
422
+
423
+ @Test
424
+ fun `FrameLayout with TextView and Button` () {
425
+ assertAST(
426
+ fileName = " framelayout-textview-button.xml" ,
427
+ Layout (
428
+ listOf (
429
+ FrameLayoutNode (
430
+ view = ViewAttributes (
431
+ width = LayoutSize .MatchParent ,
432
+ height = LayoutSize .MatchParent ,
433
+ padding = Padding (all = Size .Dp (16 ))
434
+ ),
435
+ viewGroup = ViewGroupAttributes (
436
+ children = listOf (
437
+ TextViewNode (
438
+ view = ViewAttributes (
439
+ width = LayoutSize .MatchParent ,
440
+ height = LayoutSize .MatchParent
441
+ ),
442
+ text = " Center" ,
443
+ textSize = Size .Sp (20 )
444
+ ),
445
+ ButtonNode (
446
+ view = ViewAttributes (
447
+ width = LayoutSize .MatchParent ,
448
+ height = LayoutSize .WrapContent
449
+ ),
450
+ text = " Button"
451
+ )
452
+ )
453
+
454
+ )
455
+ )
456
+ )
457
+ )
458
+ )
459
+ }
421
460
}
Original file line number Diff line number Diff line change
1
+ <FrameLayout xmlns : android =" http://schemas.android.com/apk/res/android"
2
+ android : layout_width =" match_parent"
3
+ android : layout_height =" match_parent"
4
+ android : padding =" 16dp" >
5
+
6
+ <TextView
7
+ android : layout_width =" match_parent"
8
+ android : layout_height =" match_parent"
9
+ android : gravity =" center"
10
+ android : text =" Center"
11
+ android : textSize =" 20sp" />
12
+
13
+ <Button
14
+ android : layout_width =" match_parent"
15
+ android : layout_height =" wrap_content"
16
+ android : layout_gravity =" bottom|center"
17
+ android : gravity =" bottom|center"
18
+ android : text =" Button"
19
+ android : textSize =" 20sp" />
20
+ </FrameLayout >
You can’t perform that action at this time.
0 commit comments