Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
0913fb71
Commit
0913fb71
authored
Sep 16, 2015
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1197 from Hixie/mimic
Factor out GlobalKeyWatcher
parents
f3655f34
d8668606
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
79 deletions
+90
-79
global_key_watcher.dart
packages/flutter/lib/src/widgets/global_key_watcher.dart
+78
-0
mimic.dart
packages/flutter/lib/src/widgets/mimic.dart
+11
-79
widgets.dart
packages/flutter/lib/widgets.dart
+1
-0
No files found.
packages/flutter/lib/src/widgets/global_key_watcher.dart
0 → 100644
View file @
0913fb71
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:sky/src/widgets/framework.dart'
;
abstract
class
GlobalKeyWatcher
extends
StatefulComponent
{
GlobalKeyWatcher
({
Key
key
,
this
.
watchedKey
});
GlobalKey
watchedKey
;
void
syncConstructorArguments
(
GlobalKeyWatcher
source
)
{
if
(
source
!=
source
.
watchedKey
)
{
_removeListeners
();
watchedKey
=
source
.
watchedKey
;
if
(
mounted
)
_setWatchedWidget
(
GlobalKey
.
getWidget
(
watchedKey
));
_addListeners
();
}
}
Widget
get
watchedWidget
=>
_watchedWidget
;
Widget
_watchedWidget
;
void
_setWatchedWidget
(
Widget
value
)
{
assert
(
mounted
||
value
==
null
);
if
(
watchedWidget
!=
value
)
{
if
(
watchedWidget
!=
null
)
stopWatching
();
assert
(
debugValidateWatchedWidget
(
value
));
setState
(()
{
_watchedWidget
=
value
;
});
if
(
watchedWidget
!=
null
)
startWatching
();
}
}
bool
debugValidateWatchedWidget
(
Widget
candidate
)
=>
true
;
void
didMount
()
{
super
.
didMount
();
_setWatchedWidget
(
GlobalKey
.
getWidget
(
watchedKey
));
_addListeners
();
}
void
didUnmount
()
{
super
.
didUnmount
();
_removeListeners
();
_setWatchedWidget
(
null
);
}
void
_addListeners
()
{
GlobalKey
.
registerSyncListener
(
watchedKey
,
didSyncWatchedKey
);
GlobalKey
.
registerRemoveListener
(
watchedKey
,
didRemoveWatchedKey
);
}
void
_removeListeners
()
{
GlobalKey
.
unregisterSyncListener
(
watchedKey
,
didSyncWatchedKey
);
GlobalKey
.
unregisterRemoveListener
(
watchedKey
,
didRemoveWatchedKey
);
}
void
didSyncWatchedKey
(
GlobalKey
key
,
Widget
widget
)
{
assert
(
key
==
watchedKey
);
_setWatchedWidget
(
widget
);
}
void
didRemoveWatchedKey
(
GlobalKey
key
)
{
assert
(
key
==
watchedKey
);
_setWatchedWidget
(
null
);
}
void
stopWatching
()
{
}
void
startWatching
()
{
}
}
packages/flutter/lib/src/widgets/mimic.dart
View file @
0913fb71
...
...
@@ -4,51 +4,7 @@
import
'package:sky/src/widgets/basic.dart'
;
import
'package:sky/src/widgets/framework.dart'
;
abstract
class
GlobalKeyWatcher
extends
StatefulComponent
{
GlobalKeyWatcher
({
Key
key
,
this
.
watchedKey
});
GlobalKey
watchedKey
;
void
syncConstructorArguments
(
GlobalKeyWatcher
source
)
{
if
(
source
!=
source
.
watchedKey
)
{
_removeListeners
();
watchedKey
=
source
.
watchedKey
;
_addListeners
();
}
}
void
didMount
()
{
super
.
didMount
();
_addListeners
();
}
void
didUnmount
()
{
super
.
didUnmount
();
_removeListeners
();
}
void
didSyncWatchedKey
(
GlobalKey
key
,
Widget
widget
)
{
assert
(
key
==
watchedKey
);
}
void
didRemoveWatchedKey
(
GlobalKey
key
)
{
assert
(
key
==
watchedKey
);
}
void
_addListeners
()
{
GlobalKey
.
registerSyncListener
(
watchedKey
,
didSyncWatchedKey
);
GlobalKey
.
registerRemoveListener
(
watchedKey
,
didRemoveWatchedKey
);
}
void
_removeListeners
()
{
GlobalKey
.
unregisterSyncListener
(
watchedKey
,
didSyncWatchedKey
);
GlobalKey
.
unregisterRemoveListener
(
watchedKey
,
didRemoveWatchedKey
);
}
}
import
'package:sky/src/widgets/global_key_watcher.dart'
;
typedef
MimicReadyCallback
(
);
...
...
@@ -66,48 +22,24 @@ class Mimic extends GlobalKeyWatcher {
super
.
syncConstructorArguments
(
source
);
}
Mimicable
_mimicable
;
void
didMount
()
{
super
.
didMount
();
if
(
_mimicable
==
null
)
_setMimicable
(
GlobalKey
.
getWidget
(
watchedKey
));
bool
debugValidateWatchedWidget
(
Widget
candidate
)
{
return
candidate
is
Mimicable
;
}
void
didUnmount
()
{
super
.
didUnmount
();
_stopMimic
();
}
Mimicable
get
_mimicable
=>
watchedWidget
;
void
didSyncWatchedKey
(
GlobalKey
key
,
Widget
widget
)
{
super
.
didSyncWatchedKey
(
key
,
widget
);
_setMimicable
(
widget
);
}
void
didRemoveWatchedKey
(
GlobalKey
key
)
{
super
.
didRemoveWatchedKey
(
key
);
_setMimicable
(
null
);
super
.
didSyncWatchedKey
(
key
,
widget
);
// calls startWatching()
if
(
onMimicReady
!=
null
&&
_mimicable
.
_didBuildPlaceholder
)
onMimicReady
();
}
void
_stopMimic
()
{
if
(
_mimicable
!=
null
)
{
_mimicable
.
stopMimic
();
_mimicable
=
null
;
}
void
startWatching
()
{
_mimicable
.
startMimic
();
}
void
_setMimicable
(
widget
)
{
if
(
_mimicable
!=
widget
)
{
_stopMimic
();
if
(
widget
!=
null
)
{
widget
.
startMimic
();
}
}
setState
(()
{
_mimicable
=
widget
;
});
if
(
onMimicReady
!=
null
&&
_mimicable
!=
null
&&
_mimicable
.
_didBuildPlaceholder
)
onMimicReady
();
void
stopWatching
()
{
_mimicable
.
stopMimic
();
}
Widget
build
()
{
...
...
packages/flutter/lib/widgets.dart
View file @
0913fb71
...
...
@@ -28,6 +28,7 @@ export 'package:sky/src/widgets/floating_action_button.dart';
export
'package:sky/src/widgets/focus.dart'
;
export
'package:sky/src/widgets/framework.dart'
;
export
'package:sky/src/widgets/gesture_detector.dart'
;
export
'package:sky/src/widgets/global_key_watcher.dart'
;
export
'package:sky/src/widgets/homogeneous_viewport.dart'
;
export
'package:sky/src/widgets/icon.dart'
;
export
'package:sky/src/widgets/icon_button.dart'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment