1 | import { View, CustomLayoutView } from '../core/view';
|
2 | import { layout } from '../../utils';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | export class ContentView extends CustomLayoutView {
|
8 | |
9 |
|
10 |
|
11 | get content() {
|
12 | return this._content;
|
13 | }
|
14 | set content(value) {
|
15 | const oldView = this._content;
|
16 | if (this._content) {
|
17 | this._removeView(this._content);
|
18 | }
|
19 | this._content = value;
|
20 | if (this._content) {
|
21 | this._addView(this._content);
|
22 | }
|
23 | this._onContentChanged(oldView, value);
|
24 | if (__APPLE__ && oldView !== value) {
|
25 | this.requestLayout();
|
26 | }
|
27 | }
|
28 | get layoutView() {
|
29 | let result;
|
30 | if (this._content) {
|
31 | let first = true;
|
32 | this._content._eachLayoutView((child) => {
|
33 | if (first) {
|
34 | first = false;
|
35 | result = child;
|
36 | }
|
37 | else {
|
38 | throw new Error('More than one layout child inside a ContentView');
|
39 | }
|
40 | });
|
41 | }
|
42 | return result;
|
43 | }
|
44 | get _childrenCount() {
|
45 | return this._content ? 1 : 0;
|
46 | }
|
47 |
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | _onContentChanged(oldView, newView) {
|
55 |
|
56 | }
|
57 | _addChildFromBuilder(name, value) {
|
58 | if (value instanceof View) {
|
59 | this.content = value;
|
60 | }
|
61 | }
|
62 | eachChildView(callback) {
|
63 | const content = this._content;
|
64 | if (content) {
|
65 | callback(content);
|
66 | }
|
67 | }
|
68 |
|
69 | onMeasure(widthMeasureSpec, heightMeasureSpec) {
|
70 | const result = View.measureChild(this, this.layoutView, widthMeasureSpec, heightMeasureSpec);
|
71 | const width = layout.getMeasureSpecSize(widthMeasureSpec);
|
72 | const widthMode = layout.getMeasureSpecMode(widthMeasureSpec);
|
73 | const height = layout.getMeasureSpecSize(heightMeasureSpec);
|
74 | const heightMode = layout.getMeasureSpecMode(heightMeasureSpec);
|
75 | const measureWidth = Math.max(result.measuredWidth, this.effectiveMinWidth);
|
76 | const measureHeight = Math.max(result.measuredHeight, this.effectiveMinHeight);
|
77 | const widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
|
78 | const heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
79 | this.setMeasuredDimension(widthAndState, heightAndState);
|
80 | }
|
81 |
|
82 | onLayout(left, top, right, bottom) {
|
83 | View.layoutChild(this, this.layoutView, 0, 0, right - left, bottom - top);
|
84 | }
|
85 | }
|
86 | ContentView.prototype.recycleNativeView = 'auto';
|
87 |
|
\ | No newline at end of file |