Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: lib/src/effects/swapper.dart

Issue 14295009: Fix widget.dart to work with the latest web_ui library. Specifically, query selectors need to use "… (Closed) Base URL: https://github.com/kevmoo/widget.dart.git@master
Patch Set: Updated to the next version of the SDK Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 part of effects; 1 part of effects;
2 2
3 /** 3 /**
4 * [Swapper] is an effect that builds on top of [ShowHide] to manage the visibil ity 4 * [Swapper] is an effect that builds on top of [ShowHide] to manage the visibil ity
5 * of a number of children contained in a parent element. 5 * of a number of children contained in a parent element.
6 * 6 *
7 * Provide a parent element and either a target child element or an index to a 7 * Provide a parent element and either a target child element or an index to a
8 * target child element and [Swapper] will display the target while hiding other 8 * target child element and [Swapper] will display the target while hiding other
9 * visible elements using the provided effects, duration, and timing. 9 * visible elements using the provided effects, duration, and timing.
10 * 10 *
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 33
34 if(child.parent != host) { 34 if(child.parent != host) {
35 throw 'host is not the parent of the provided child'; 35 throw 'host is not the parent of the provided child';
36 } 36 }
37 37
38 // ensure at most one child of the host is visible before beginning 38 // ensure at most one child of the host is visible before beginning
39 return _ensureOneShown(host) 39 return _ensureOneShown(host)
40 .then((Element currentlyVisible) { 40 .then((Element currentlyVisible) {
41 if(currentlyVisible == null) { 41 if(currentlyVisible == null) {
42 return new Future.immediate(false); 42 return new Future.value(false);
43 } else if(currentlyVisible == child) { 43 } else if(currentlyVisible == child) {
44 // target element is already shown 44 // target element is already shown
45 return new Future.immediate(true); 45 return new Future.value(true);
46 } 46 }
47 47
48 child.style.zIndex = '2'; 48 child.style.zIndex = '2';
49 final showFuture = ShowHide.show(child, effect: effect, duration: dura tion, effectTiming: effectTiming); 49 final showFuture = ShowHide.show(child, effect: effect, duration: dura tion, effectTiming: effectTiming);
50 50
51 currentlyVisible.style.zIndex = '1'; 51 currentlyVisible.style.zIndex = '1';
52 final hideFuture = ShowHide.hide(currentlyVisible, effect: hideEffect, duration: duration, effectTiming: effectTiming); 52 final hideFuture = ShowHide.hide(currentlyVisible, effect: hideEffect, duration: duration, effectTiming: effectTiming);
53 53
54 return Future.wait([showFuture, hideFuture]) 54 return Future.wait([showFuture, hideFuture])
55 .then((List<ShowHideResult> results) { 55 .then((List<ShowHideResult> results) {
56 [child, currentlyVisible].forEach((e) => e.style.zIndex = ''); 56 [child, currentlyVisible].forEach((e) => e.style.zIndex = '');
57 return results.every((a) => a.isSuccess); 57 return results.every((a) => a.isSuccess);
58 }); 58 });
59 }); 59 });
60 } 60 }
61 61
62 static Future<bool> _hideEverything(Element host, ShowHideEffect effect, int d uration, EffectTiming effectTiming) { 62 static Future<bool> _hideEverything(Element host, ShowHideEffect effect, int d uration, EffectTiming effectTiming) {
63 final futures = host.children.map((e) => ShowHide.hide(e, effect: effect, du ration: duration, effectTiming: effectTiming)).toList(); 63 final futures = host.children.map((e) => ShowHide.hide(e, effect: effect, du ration: duration, effectTiming: effectTiming)).toList();
64 return Future.wait(futures) 64 return Future.wait(futures)
65 .then((List<ShowHideResult> successList) { 65 .then((List<ShowHideResult> successList) {
66 return successList.every((v) => v.isSuccess); 66 return successList.every((v) => v.isSuccess);
67 }); 67 });
68 } 68 }
69 69
70 static Future<Element> _ensureOneShown(Element host) { 70 static Future<Element> _ensureOneShown(Element host) {
71 assert(host != null); 71 assert(host != null);
72 if(host.children.length == 0) { 72 if(host.children.length == 0) {
73 // no elements to show 73 // no elements to show
74 return new Future.immediate(null); 74 return new Future.value(null);
75 } else if(host.children.length == 1) { 75 } else if(host.children.length == 1) {
76 final child = host.children[0]; 76 final child = host.children[0];
77 return ShowHide.show(child) 77 return ShowHide.show(child)
78 .then((ShowHideResult result) { 78 .then((ShowHideResult result) {
79 if(result.isSuccess) { 79 if(result.isSuccess) {
80 return child; 80 return child;
81 } else { 81 } else {
82 return null; 82 return null;
83 } 83 }
84 }); 84 });
85 } 85 }
86 86
87 // 1 - get states of all children 87 // 1 - get states of all children
88 final theStates = host.children 88 final theStates = host.children
89 .map(ShowHide.getState).toList(); 89 .map(ShowHide.getState).toList();
90 90
91 int shownIndex = null; 91 int shownIndex = null;
92 92
93 return new Future.immediate(theStates) 93 return new Future.value(theStates)
94 .then((List<ShowHideState> states) { 94 .then((List<ShowHideState> states) {
95 // paranoid sanity check that at lesat the count of items 95 // paranoid sanity check that at lesat the count of items
96 // before and after haven't changed 96 // before and after haven't changed
97 assert(states.length == host.children.length); 97 assert(states.length == host.children.length);
98 98
99 // See how many of the items are actually shown 99 // See how many of the items are actually shown
100 final showIndicies = new List<int>(); 100 final showIndicies = new List<int>();
101 for(int i=0; i<states.length;i++) { 101 for(int i=0; i<states.length;i++) {
102 if(states[i].isShow) { 102 if(states[i].isShow) {
103 showIndicies.add(i); 103 showIndicies.add(i);
(...skipping 30 matching lines...) Expand all
134 } 134 }
135 }); 135 });
136 } 136 }
137 137
138 static Future<bool> _hideAll(List<Element> elements) { 138 static Future<bool> _hideAll(List<Element> elements) {
139 final futures = elements.map((Element e) => ShowHide.hide(e)).toList(); 139 final futures = elements.map((Element e) => ShowHide.hide(e)).toList();
140 return Future.wait(futures) 140 return Future.wait(futures)
141 .then((List<ShowHideResult> successValues) => successValues.every((v) => v.isSuccess)); 141 .then((List<ShowHideResult> successValues) => successValues.every((v) => v.isSuccess));
142 } 142 }
143 } 143 }
OLDNEW
« no previous file with comments | « lib/src/effects/show_hide.dart ('k') | pubspec.yaml » ('j') | pubspec.yaml » ('J')

Powered by Google App Engine
This is Rietveld 408576698