This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Commit e3b2782
authored
[macOS] Formalize FlutterViewController's initialization flow, and prohibit replacing (#38981)
This PR adds FlutterViewController.id, and formalizes how FlutterViewController is initialized by FlutterEngine:
When FlutterViewController is set to the engine, the engine calls FlutterViewController#attachToEngine:withId:.
When FlutterViewController is unset from the engine, the engine calls FlutterViewController#detachFromEngine.
This allows the ID to be generated by the engine.
The default View ID is now 1 instead of 0. In this way, we can use 0 as an empty value, the value for FlutterViewController.id when the FVC is not attached to an engine. (IDs are meant to be opaque, and views should be a map, not an array anyway.)
This PR moves almost all initialization code into FVC's CommonInit to ensure that all init path produces the expected result.
With this PR, FlutterEngine no long supports replacing viewController (from non-null to a different non-null). Setting the view controller (from null to non-null) is intended to allow pre-warming an engine before displaying it in add-to-app, but replacing the view controller does not make much sense.
If the developer wants to persist the state of the view between different windows, they could just attach the view controller to different windows.
In fact, Flutter doesn't even have a way to create a FlutterViewController that is unattached to an engine. All initializers either require an engine or create an engine.
As a result, unit tests that used to create FVC with the wrong initializer are fixed.1 parent 308ce91 commit e3b2782
File tree
14 files changed
+282
-301
lines changed- shell/platform/darwin/macos/framework
- Headers
- Source
14 files changed
+282
-301
lines changedLines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
18 | 31 | | |
19 | 32 | | |
20 | 33 | | |
| |||
67 | 80 | | |
68 | 81 | | |
69 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
70 | 92 | | |
71 | 93 | | |
72 | 94 | | |
| |||
Lines changed: 43 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
28 | 47 | | |
29 | 48 | | |
30 | 49 | | |
| |||
34 | 53 | | |
35 | 54 | | |
36 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
37 | 66 | | |
38 | 67 | | |
39 | 68 | | |
| |||
43 | 72 | | |
44 | 73 | | |
45 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
46 | 81 | | |
47 | 82 | | |
48 | 83 | | |
| |||
56 | 91 | | |
57 | 92 | | |
58 | 93 | | |
59 | | - | |
| 94 | + | |
| 95 | + | |
60 | 96 | | |
61 | 97 | | |
62 | 98 | | |
| |||
65 | 101 | | |
66 | 102 | | |
67 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
68 | 110 | | |
69 | 111 | | |
70 | 112 | | |
| |||
Lines changed: 11 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
60 | | - | |
61 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 67 | + | |
| 68 | + | |
72 | 69 | | |
73 | | - | |
74 | 70 | | |
75 | 71 | | |
76 | 72 | | |
| |||
122 | 118 | | |
123 | 119 | | |
124 | 120 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 121 | + | |
| 122 | + | |
131 | 123 | | |
132 | | - | |
133 | 124 | | |
134 | 125 | | |
135 | 126 | | |
| |||
173 | 164 | | |
174 | 165 | | |
175 | 166 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 167 | + | |
| 168 | + | |
183 | 169 | | |
184 | | - | |
185 | 170 | | |
186 | 171 | | |
187 | 172 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
Lines changed: 46 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
| 85 | + | |
| 86 | + | |
83 | 87 | | |
84 | 88 | | |
85 | 89 | | |
| |||
213 | 217 | | |
214 | 218 | | |
215 | 219 | | |
216 | | - | |
217 | | - | |
218 | 220 | | |
219 | 221 | | |
220 | 222 | | |
| |||
248 | 250 | | |
249 | 251 | | |
250 | 252 | | |
251 | | - | |
252 | 253 | | |
253 | 254 | | |
254 | 255 | | |
| |||
411 | 412 | | |
412 | 413 | | |
413 | 414 | | |
414 | | - | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
415 | 427 | | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
422 | 434 | | |
423 | 435 | | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
424 | 444 | | |
425 | 445 | | |
426 | 446 | | |
427 | 447 | | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
| 448 | + | |
| 449 | + | |
437 | 450 | | |
438 | 451 | | |
439 | 452 | | |
| |||
539 | 552 | | |
540 | 553 | | |
541 | 554 | | |
542 | | - | |
| 555 | + | |
543 | 556 | | |
544 | 557 | | |
545 | | - | |
| 558 | + | |
546 | 559 | | |
547 | 560 | | |
548 | 561 | | |
| |||
603 | 616 | | |
604 | 617 | | |
605 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
606 | 630 | | |
607 | 631 | | |
608 | 632 | | |
| |||
679 | 703 | | |
680 | 704 | | |
681 | 705 | | |
682 | | - | |
683 | | - | |
684 | | - | |
| 706 | + | |
685 | 707 | | |
686 | 708 | | |
687 | 709 | | |
| |||
0 commit comments