This introduces a GlobalKey registry so that you can tell when a key
has gone away (so you can unfocus dead dialogs).
Also I added an assert that you're not calling setState() during a
build. It turns out that doing so means you have a bug, because since
you're dirty already (you're building), you won't get rebuilt.
The focus code itself is gnarly. It uses a Component and an internal
Inherited TagNode to manage the focus state, and does crazy things
like updating its state during build to pretend retroactively that it
was built with some other state, once someone asks for focus the first
time (i.e. the first time it's examined, so you can't tell that it was
in a different state before). It does this so that it can autofocus
controls which otherwise wouldn't be focused.
This moves all the focus management into Navigator and showDialog(),
so the complexity is all buried deep and not visible to apps,
hopefully.
To do something like two tabs that each have an Input widget that
needs to be focused when you switch panes, you'd need to have two
Focus objects, one in each tab, and you need to set their autofocus to
true (maybe that should be the default?).
This removes the need to manually include the dialog builder in the main window's build() function.
It also removes the need to track if a dialog is visible.
Other changes:
- I made dialog.dart a bit more readable.
- I renamed transitionFinished to fullyOpaque since that's what actually matters.
- I made Routes track if they're opaque. Eventually this should probably be more configurable when creating the route.
Directions for Future Research:
- Use this for focus management somehow.
- The popup menu should use something like this.
- We should factor the following out into a showDialog() function that returns a future for the dialog's exit result:
navigator.push(new DialogRoute(builder: (navigator, route) { ... }));
- Maybe navigator.pop() should take a value to return to that Future.
Converted demo launcher example to library
Converted fitness example to library
Converted hello world example to library
Converted mine digger example to library
Converted stocks example to library
This CL introduces a SkyShell.apk that is separate from the SkyDemo.apk that we
upload to the store to show our demos. The SkyShell.apk is just an empty shell
that can run Sky applications on Android.
I've noticed an anti-pattern emerge where people call scheduleBuild()
when they think they've changed enough state that they should rebuild,
instead of just wrapping their changes in setState(). This leads to
them missing state changes, having extraneous scheduleBuild() calls,
and other similar bugs.
By removing scheduleBuild(), the only way to actually schedule a build
now is to call setState(), and hopefully that'll make it much clearer
that you're only supposed to do this when you change state.
This is supposed to make Viktor's game faster, but it's not clear
to me that it actually does. I've left the code
using the dart version of drawAtlas for now until Viktor can
verify that it looks correct.
I also added a wrapper for SkFilterQuality in the process of
debugging SkCanvas.drawAtlas since all drawAtlas examples
in Skia use FilterQuality.low. The bug which blocked me for
so long turned out to be that SkCanvas.drawAtlas doesn't
draw anything if antialiasing is turned on.
Issue #138.
R=abarth@google.com
This patch provides a class to manage focus, Focus, and a class to
manage ownership of the keyboard, KeyboardHandle.
Inherited (in widgets.dart) is adjusted to support subclasses that
need to copy state from instance to instance.
A GlobalKey key type is introduced that is basically the same as
UniqueKey. Component classes that need a globally-unique key can
specify that their 'key' constructor argument is a GlobalKey.
Focus
-----
You can use `Focus.at(this)` to determine if you, a Component, are
currently focused.
You can use `Focus.moveTo(this)` to take the focus or give it to a
particular component.
For this to work, there has to be a Focus class in the widget
hierarchy.
Currently, there can only be one Focus class, because nested scopes
aren't supported. We should add support for that in a future patch.
See issue #229.
KeyboardHandle
--------------
Instead of directly interacting with the keyboard service, you now ask
for a KeyboardHandle using `_keyboard.show(client)`. This returns a
KeyboardHandle class. On that class, you can call `handle.release()`
when you want to hide the keyboard. If `handle.attached` is still
true, and you need to reshow the keyboard after the user hid it, then
you can can `handle.showByRequest()`.
The point of this is that the `keyboard.show()` method maintains the
invariant that only one KeyboardHandle is live at a time.
There are some issues with the keyboard service that I filed as a
result of doing this patch: #226#227
Make SnackBar animate itself.
This introduces a bit of a regression - the FloatingActionButton no longer animates. I'm not sure yet how to animated the FAB along with the SnackBar. Maybe some notion of anchoring a node to another.
Also remove last use of AnimationBuilder.
This fixes some theoretical bugs whereby we were using hashCode to try
to get unique keys for objects, but really we wanted object identity.
It also lays the groundwork for a new GlobalKey concept.
I tried to keep the impact on the code minimal, which is why the "Key"
constructor is actually a factory that returns a StringKey. The code
has this class hierarchy:
```
KeyBase
|
Key--------------+---------------+
| | |
StringKey ObjectKey UniqueKey
```
...where the constructors are Key and Key.stringify (StringKey),
Key.fromObjectIdentity (ObjectKey), and Key.unique (UniqueKey).
We could instead of factory methods use regular constructors with the
following hierarchy:
```
KeyBase
|
LocalKey---------+---------------+
| | |
Key ObjectIdentityKey UniqueKey
```
...with constructors Key, Key.stringify, ObjectIdentityKey, and
UniqueKey, but I felt that that was maybe a more confusing hierarchy.
I don't have a strong opinion on this.
Text styles are now a global constant instead of being initialised dynamically.
There are now sufficient text styles for 8 mines around a square.
I coallesced Game and MineDiggerApp.
Used an enum instead of constants for the cell state.
Used setState() instead of scheduleBuild().
Used an O(N) algorithm for mine laying instead of the previous potentially-never-ending algorithm.
Moved the listener on the cells to the app, so that the logic survives a rebuild.
Various other minor changes.