@neovici/cosmoz-bottom-bar 4.0.6 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,8 @@
1
1
  import { component } from 'haunted';
2
2
  import { html } from 'lit-html';
3
3
  import { ifDefined } from 'lit-html/directives/if-defined';
4
- import { ref } from '@neovici/cosmoz-utils/lib/directives/ref';
5
- import { useBottomBarView } from './lib/use-bottom-bar-view';
6
4
  import { bottomBarSlots } from './cosmoz-bottom-bar';
7
5
 
8
-
9
-
10
6
  /**
11
7
  * `cosmoz-bottom-bar-view` contains a content section and a bottom bar with actions.
12
8
  *
@@ -18,49 +14,41 @@ import { bottomBarSlots } from './cosmoz-bottom-bar';
18
14
  */
19
15
 
20
16
  const CosmozBottomBarView = ({
21
- barHeight,
22
- ...pass
23
- }) => { /*eslint-disable no-return-assign */
24
- const {
25
- active,
26
- info
27
- } = useBottomBarView(pass);
28
-
29
- return html`
30
- <style>
31
- :host {
32
- position: relative;
33
- display: flex;
34
- flex-direction: column;
35
- flex: var(--cosmoz-bottom-bar-view-flex, auto);
36
- overflow: hidden;
37
- }
38
-
39
- #content {
40
- display: flex;
41
- flex-direction: column;
42
- flex: auto;
43
- -webkit-overflow-scrolling: touch;
44
- overflow-y: auto;
45
- }
46
-
47
- #bar {
48
- background-color: var(--cosmoz-bottom-bar-view-bar-color, rgba(230, 230, 230, 0.8));
49
- box-shadow: var(--cosmoz-bottom-bar-view-bar-shadow, none);
50
- position: static;
51
- flex: none;
52
- }
53
- </style>
54
- <div id="content" part="content">
55
- ${ ref(info) }
56
- <slot name="content"></slot>
57
- <slot name="scroller-content"></slot>
58
- </div>
59
- <cosmoz-bottom-bar id="bar" ?active=${ active } bar-height=${ ifDefined(barHeight) } part="bar">
60
- <slot></slot>
61
- ${ bottomBarSlots }
62
- </cosmoz-bottom-bar>
63
- `;
64
- };
17
+ active = true,
18
+ barHeight
19
+ }) => html`
20
+ <style>
21
+ :host {
22
+ position: relative;
23
+ display: flex;
24
+ flex-direction: column;
25
+ flex: var(--cosmoz-bottom-bar-view-flex, auto);
26
+ overflow: hidden;
27
+ }
28
+
29
+ #content {
30
+ display: flex;
31
+ flex-direction: column;
32
+ flex: auto;
33
+ -webkit-overflow-scrolling: touch;
34
+ overflow-y: auto;
35
+ }
36
+
37
+ #bar {
38
+ background-color: var(--cosmoz-bottom-bar-view-bar-color, rgba(230, 230, 230, 0.8));
39
+ box-shadow: var(--cosmoz-bottom-bar-view-bar-shadow, none);
40
+ position: static;
41
+ flex: none;
42
+ }
43
+ </style>
44
+ <div id="content" part="content">
45
+ <slot name="content"></slot>
46
+ <slot name="scroller-content"></slot>
47
+ </div>
48
+ <cosmoz-bottom-bar id="bar" ?active=${ active } bar-height=${ ifDefined(barHeight) } part="bar">
49
+ <slot></slot>
50
+ ${ bottomBarSlots }
51
+ </cosmoz-bottom-bar>
52
+ `;
65
53
  customElements.define('cosmoz-bottom-bar-view', component(CosmozBottomBarView));
66
54
 
@@ -1,10 +1,4 @@
1
- import '@webcomponents/shadycss/entrypoints/apply-shim';
2
-
3
- import '@polymer/iron-icons';
4
- import '@polymer/paper-icon-button';
5
- import '@polymer/paper-menu-button';
6
- import '@polymer/paper-listbox';
7
- import '@polymer/iron-selector/iron-selector';
1
+ import '@neovici/cosmoz-dropdown';
8
2
 
9
3
  import { html } from '@polymer/polymer/lib/utils/html-tag';
10
4
  export default html`
@@ -19,49 +13,35 @@ export default html`
19
13
  background-color: inherit;
20
14
  transition: max-height 0.3s ease;
21
15
  z-index: 10;
16
+ --cosmoz-dropdown-spacing: 0 0 5px 0;
22
17
  }
23
18
 
24
19
  [hidden] {
25
20
  display: none !important;
26
21
  }
27
22
 
28
- #bar, #info, #toolbar, #extraToolbarSlot, #menu, #dropdown ::slotted(:not(slot)) {
29
- display: flex;
30
- align-items: center;
31
- }
32
23
 
33
24
  #bar {
34
25
  padding: 0 3%;
26
+ display: flex;
27
+ align-items: center;
35
28
  }
36
29
 
37
30
  #info {
38
31
  min-width: 5px;
39
32
  padding-right: 3%;
33
+ margin-right: auto;
34
+ white-space: nowrap;
40
35
  }
41
36
 
42
- #dropdownButton {
43
- color: var(--cosmoz-bottom-bar-menubutton-color, var(--light-primary-color));
44
- background-color: var(--cosmoz-bottom-bar-menubutton-background-color, var(--dark-primary-color));
45
- @apply --cosmoz-bottom-bar-menubutton;
46
- }
47
-
48
- #extraToolbarSlot ::slotted(:not(slot)) {
49
- @apply --cosmoz-bottom-bar-extra-toolbar-item;
50
- }
51
-
52
- #flex {
53
- flex: 1 0.000000000001px;
54
- }
55
-
56
- #toolbar, #extraToolbarSlot {
57
- overflow: hidden;
58
- }
59
- #info,
60
- #menu > div {
61
- white-space: nowrap;
37
+ ::slotted([disabled]) {
38
+ @apply --cosmoz-bottom-bar-toolbar-item-disabled;
62
39
  }
40
+ ::slotted([hidden]) {
41
+ display: none !important;
42
+ }
63
43
 
64
- #toolbar ::slotted(:not(slot)) {
44
+ #bottomBarToolbar::slotted(:not(slot)) {
65
45
  margin: 0 0.29em;
66
46
  min-width: 40px;
67
47
  min-height: 40px;
@@ -70,54 +50,39 @@ export default html`
70
50
  @apply --cosmoz-bottom-bar-toolbar-item;
71
51
  }
72
52
 
73
- #toolbar ::slotted([disabled]),
74
- #dropdown ::slotted([disabled]) {
75
- @apply --cosmoz-bottom-bar-toolbar-item-disabled;
76
- }
77
-
78
- #toolbar ::slotted([hidden]),
79
- #dropdown ::slotted([hidden]) {
80
- display: none !important;
81
- }
82
-
83
- #dropdown {
84
- padding: 0;
85
- }
86
-
87
- /** Seems like a shady dom scoping/slotting issue */
88
- #listboxSizer {
89
- max-height: 0;
90
- padding: 0 !important;
91
- }
92
-
93
- #dropdown ::slotted(:not(slot)) {
53
+ #dropdown::part(anchor) {
54
+ padding: 12px 8px;
55
+ }
56
+ #dropdown::part(dropdown) {
57
+ max-width: 300px;
58
+ }
59
+ #bottomBarMenu::slotted(:not(slot)) {
94
60
  position: relative;
61
+ cursor: pointer;
95
62
  @apply --cosmoz-bottom-bar-menu-item;
96
63
  }
64
+ #bottomBarMenu::slotted(:not(slot):hover) {
65
+ background: #eee;
66
+ }
67
+
97
68
  </style>
98
69
 
99
- <div id="bar" style$="[[ _getHeightStyle(computedBarHeight) ]]">
70
+ <div id="bar" style$="[[ _getHeightStyle(computedBarHeight) ]]" part="bar">
100
71
  <div id="info">
101
- <slot name="info"></slot>
72
+ <slot name="info"></slot>
73
+ </div>
74
+ <slot id="bottomBarToolbar" name="bottom-bar-toolbar"></slot>
75
+ <cosmoz-dropdown id="dropdown" hidden="[[ !hasMenuItems ]]" placement="[[ topPlacement ]]">
76
+ <svg slot="button" width="4" height="16" viewBox="0 0 4 16" fill="none" xmlns="http://www.w3.org/2000/svg">
77
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M1.50996e-07 2C1.02714e-07 3.10457 0.89543 4 2 4C3.10457 4 4 3.10457 4 2C4 0.89543 3.10457 -3.91405e-08 2 -8.74228e-08C0.895431 -1.35705e-07 1.99278e-07 0.89543 1.50996e-07 2Z" fill="white"/>
78
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M1.50996e-07 8C1.02714e-07 9.10457 0.89543 10 2 10C3.10457 10 4 9.10457 4 8C4 6.89543 3.10457 6 2 6C0.895431 6 1.99278e-07 6.89543 1.50996e-07 8Z" fill="white"/>
79
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M1.50996e-07 14C1.02714e-07 15.1046 0.89543 16 2 16C3.10457 16 4 15.1046 4 14C4 12.8954 3.10457 12 2 12C0.895431 12 1.99278e-07 12.8954 1.50996e-07 14Z" fill="white"/>
80
+ </svg>
81
+ <slot id="bottomBarMenu" name="bottom-bar-menu"></slot>
82
+ </cosmoz-dropdown>
83
+ <div id="extraToolbarSlot">
84
+ <slot name="extra" id="extraSlot"></slot>
102
85
  </div>
103
- <div id="flex"></div>
104
- <iron-selector id="toolbar" selected-class="[[ selectedClass ]]" on-iron-select="_onActionSelected">
105
- <slot id="bottomBarToolbar" name="bottom-bar-toolbar"></slot>
106
- </iron-selector>
107
- <paper-menu-button id="menu" hidden$="[[ !hasMenuItems ]]" no-animations
108
- vertical-offset="[[ barHeight ]]" vertical-align="bottom" horizontal-align="right">
109
-
110
- <paper-icon-button id="dropdownButton" class="dropdown-trigger" slot="dropdown-trigger" icon="menu" toggles raised>
111
- </paper-icon-button>
112
- <paper-listbox id="dropdown" class="dropdown-content" slot="dropdown-content"
113
- selected-class="[[ selectedClass ]]" on-iron-select="_onActionSelected">
114
- <span id="listboxSizer"></span>
115
- <slot id="bottomBarMenu" name="bottom-bar-menu"></slot>
116
- </paper-listbox>
117
- </paper-menu-button>
118
- <iron-selector id="extraToolbarSlot" on-iron-select="_onActionSelected">
119
- <slot name="extra" id="extraSlot"></slot>
120
- </iron-selector>
121
86
  </div>
122
87
 
123
88
  <div hidden style="display:none">
@@ -7,12 +7,11 @@ import { Debouncer } from '@polymer/polymer/lib/utils/debounce.js';
7
7
  import { timeOut } from '@polymer/polymer/lib/utils/async';
8
8
  import template from './cosmoz-bottom-bar.html.js';
9
9
  import { html } from 'haunted';
10
+ import { defaultPlacement } from '@neovici/cosmoz-dropdown';
10
11
 
11
12
  const
12
13
  BOTTOM_BAR_TOOLBAR_SLOT = 'bottom-bar-toolbar',
13
- BOTTOM_BAR_MENU_SLOT = 'bottom-bar-menu',
14
-
15
- slotEq = slot => element => element.getAttribute('slot') === slot;
14
+ BOTTOM_BAR_MENU_SLOT = 'bottom-bar-menu';
16
15
 
17
16
  /**
18
17
  * `<cosmoz-bottom-bar>` is a horizontal responsive bottom toolbar containing items that
@@ -157,6 +156,10 @@ class CosmozBottomBar extends PolymerElement {
157
156
  _matchHeightElement: {
158
157
  type: Object,
159
158
  computed: '_getHeightMatchingElement(matchParent)'
159
+ },
160
+
161
+ topPlacement: {
162
+ value: ['top-right', ...defaultPlacement]
160
163
  }
161
164
  };
162
165
  }
@@ -169,7 +172,6 @@ class CosmozBottomBar extends PolymerElement {
169
172
 
170
173
  constructor() {
171
174
  super();
172
- this._boundDropdownClosed = this._dropdownClosed.bind(this);
173
175
  this._boundChildrenUpdated = this._childrenUpdated.bind(this);
174
176
  this._boundLayoutActions = this._layoutActions.bind(this);
175
177
  this._resizeObserver = new ResizeObserver((...args) => {
@@ -181,16 +183,15 @@ class CosmozBottomBar extends PolymerElement {
181
183
  connectedCallback() {
182
184
  super.connectedCallback();
183
185
 
184
- this.addEventListener('iron-closed-overlay', this._boundDropdownClosed);
185
186
 
186
- this._hiddenMutationObserver = new MutationObserver(() => {
187
- this._overflowWidth = undefined;
188
- this._debounceLayoutActions();
189
- });
190
- this._nodeObserver = new FlattenedNodesObserver(this.$.content, this._boundChildrenUpdated);
191
- this._nodeObserverExtra = new FlattenedNodesObserver(this.$.extraSlot, info =>
192
- this.set('hasExtraItems', info.addedNodes.length > 0)
193
- );
187
+ const layoutOnRemove = info => info.removedNodes.filter(this._isActionNode) && this._debounceLayoutActions();
188
+ this._nodeObservers = [
189
+ new FlattenedNodesObserver(this.$.content, this._boundChildrenUpdated),
190
+ new FlattenedNodesObserver(this.$.extraSlot, info => this.set('hasExtraItems', info.addedNodes.length > 0)),
191
+ new FlattenedNodesObserver(this.$.bottomBarToolbar, layoutOnRemove),
192
+ new FlattenedNodesObserver(this.$.bottomBarMenu, layoutOnRemove)
193
+ ];
194
+ this._hiddenMutationObserver = new MutationObserver(() => this._debounceLayoutActions());
194
195
  this._resizeObserver.observe(this);
195
196
  this._computedBarHeightKicker = 0;
196
197
  }
@@ -198,35 +199,19 @@ class CosmozBottomBar extends PolymerElement {
198
199
  disconnectedCallback() {
199
200
  super.disconnectedCallback();
200
201
 
201
- this.removeEventListener('iron-closed-overlay', this._boundDropdownClosed);
202
-
203
- this._nodeObserver.disconnect();
204
- this._nodeObserverExtra.disconnect();
205
- this._hiddenMutationObserver.disconnect();
202
+ [...this._nodeObservers, this._hiddenMutationObserver].forEach(e => e.disconnect(e));
206
203
  this._layoutDebouncer?.cancel(); /* eslint-disable-line no-unused-expressions */
207
204
  this._resizeObserver.unobserve(this);
208
205
  }
209
206
 
210
- _canAddMoreButtonToBar(width, bottomBarElements, menuElements) {
211
- const hasSpace = width > this._overflowWidth || this._overflowWidth === undefined,
212
- hasPlace = bottomBarElements.length < this.maxToolbarItems,
213
- hasCandidates = menuElements.length > 0;
214
-
215
- return hasSpace && hasPlace && hasCandidates;
216
- }
217
-
218
207
  _childrenUpdated(info) {
219
208
  const addedNodes = info.addedNodes.filter(this._isActionNode),
220
209
  removedNodes = info.removedNodes.filter(this._isActionNode),
221
210
  newNodes = addedNodes.filter(node => !removedNodes.includes(node));
222
211
 
223
- if (addedNodes.length === 0 && removedNodes.length === 0) {
212
+ if (addedNodes.length === 0 && removedNodes.length === 0 || newNodes.length === 0) {
224
213
  return;
225
214
  }
226
- if (newNodes.length === 0) {
227
- return;
228
- }
229
-
230
215
  newNodes.forEach(node => {
231
216
  this._hiddenMutationObserver.observe(node, {
232
217
  attributes: true,
@@ -235,20 +220,10 @@ class CosmozBottomBar extends PolymerElement {
235
220
  this._moveElement(node, false);
236
221
  });
237
222
 
238
- const toolbarElements = this._getElements().filter(slotEq(BOTTOM_BAR_TOOLBAR_SLOT)),
239
- toolbarCount = this.maxToolbarItems - toolbarElements.length;
240
-
241
- if (toolbarCount > 0) {
242
- newNodes
243
- .filter(node => !node.hidden).slice(0, toolbarCount)
244
- .forEach(node => this._moveElement(node, true));
245
- }
246
-
247
223
  this._debounceLayoutActions();
248
224
  }
249
225
 
250
- // eslint-disable-next-line no-unused-vars
251
- _computeComputedBarHeight(matchElementHeight, barHeight, kicker) {
226
+ _computeComputedBarHeight(matchElementHeight, barHeight) {
252
227
  if (matchElementHeight) {
253
228
  return matchElementHeight.offsetHeight;
254
229
  }
@@ -267,17 +242,8 @@ class CosmozBottomBar extends PolymerElement {
267
242
  );
268
243
  }
269
244
 
270
- _dropdownClosed() {
271
- this.$.dropdownButton.active = false;
272
- }
273
-
274
245
  _fireAction(item) {
275
-
276
- if (!item || !item.dispatchEvent) {
277
- return;
278
- }
279
-
280
- item.dispatchEvent(new window.CustomEvent('action', {
246
+ item?.dispatchEvent?.(new window.CustomEvent('action', {
281
247
  bubbles: true,
282
248
  cancelable: true,
283
249
  detail: {
@@ -311,7 +277,8 @@ class CosmozBottomBar extends PolymerElement {
311
277
  _getElements() {
312
278
  return FlattenedNodesObserver.getFlattenedNodes(this)
313
279
  .filter(this._isActionNode)
314
- .filter(element => !element.hidden);
280
+ .filter(element => !element.hidden)
281
+ .sort((a, b) => a.dataset.index - b.dataset.index);
315
282
  }
316
283
  /**
317
284
  * Layout the actions available as buttons or menu items
@@ -335,56 +302,19 @@ class CosmozBottomBar extends PolymerElement {
335
302
  */
336
303
  _layoutActions() { // eslint-disable-line max-statements
337
304
  const elements = this._getElements(),
338
- toolbar = this.$.toolbar;
305
+ hasActions = elements.length > 0 || this.hasExtraItems;
306
+ this._setHasActions(hasActions);
339
307
 
340
- let fits,
341
- newToolbarElement;
342
-
343
- this._setHasActions(elements.length > 0 || this.hasExtraItems);
344
- if (!this.hasActions) {
308
+ if (!hasActions) {
345
309
  // No need to render if we don't have any actions
346
- return;
310
+ return this._setHasMenuItems(false);
347
311
  }
348
312
 
349
- const currentWidth = toolbar.clientWidth;
350
- fits = toolbar.scrollWidth <= currentWidth + 1;
351
-
352
- const toolbarElements = elements.filter(slotEq(BOTTOM_BAR_TOOLBAR_SLOT)),
353
- menuElements = elements.filter(slotEq(BOTTOM_BAR_MENU_SLOT));
354
-
313
+ const toolbarElements = elements.slice(0, this.maxToolbarItems),
314
+ menuElements = elements.slice(toolbarElements.length);
315
+ toolbarElements.forEach(el => this._moveElement(el, true));
316
+ menuElements.forEach(el => this._moveElement(el));
355
317
  this._setHasMenuItems(menuElements.length > 0);
356
-
357
- fits = fits && toolbarElements.length <= this.maxToolbarItems;
358
- fits = fits && toolbarElements.every(element => element.scrollWidth <= element.clientWidth);
359
-
360
-
361
- if (fits) {
362
- if (this._canAddMoreButtonToBar(currentWidth, toolbarElements, menuElements)) {
363
- newToolbarElement = menuElements[0];
364
- this._moveElement(newToolbarElement, true);
365
- // (pasleq) If we are moving the focused element from the menu to the toolbar
366
- // while the toolbar is open, this will cause an error in iron-control-state
367
- // that tries to handle lost of focus on an element that has been removed.
368
- if (toolbarElements.length > 0) {
369
- toolbarElements[0].focus();
370
- } else {
371
- newToolbarElement.focus();
372
- }
373
- this.$.menu.close();
374
- this._debounceLayoutActions();
375
- }
376
- return;
377
- }
378
-
379
- this._overflowWidth = currentWidth;
380
-
381
- if (toolbarElements.length < 1) {
382
- return;
383
- }
384
-
385
- const newMenuElement = toolbarElements[toolbarElements.length - 1];
386
- this._moveElement(newMenuElement, false);
387
- this._debounceLayoutActions();
388
318
  }
389
319
 
390
320
  _moveElement(element, toToolbar) {
@@ -408,7 +338,6 @@ class CosmozBottomBar extends PolymerElement {
408
338
  return;
409
339
  }
410
340
  this._computedBarHeightKicker += 1;
411
- this._debounceLayoutActions();
412
341
  }
413
342
 
414
343
  _showHideBottomBar(visible) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-bottom-bar",
3
- "version": "4.0.6",
3
+ "version": "4.3.0",
4
4
  "description": "A responsive bottom-bar that can house buttons/actions and a menu for the buttons that won't fit the available width.",
5
5
  "keywords": [
6
6
  "polymer",
@@ -51,35 +51,28 @@
51
51
  ]
52
52
  },
53
53
  "dependencies": {
54
- "@neovici/cosmoz-utils": "^3.12.0",
55
- "@neovici/cosmoz-viewinfo": "^3.1.3",
56
- "@polymer/iron-icons": "^3.0.1",
57
- "@polymer/iron-selector": "^3.0.0",
58
- "@polymer/paper-icon-button": "^3.0.0",
59
- "@polymer/paper-listbox": "^3.0.0",
60
- "@polymer/paper-menu-button": "^3.0.0",
54
+ "@neovici/cosmoz-dropdown": "^1.1.0",
61
55
  "@polymer/polymer": "^3.3.1",
62
- "@webcomponents/shadycss": "^1.10.2",
63
56
  "haunted": "^4.8.0",
64
57
  "lit-html": "^1.4.0"
65
58
  },
66
59
  "devDependencies": {
67
- "@commitlint/cli": "^12.0.0",
68
- "@commitlint/config-conventional": "^12.0.0",
60
+ "@commitlint/cli": "^15.0.0",
61
+ "@commitlint/config-conventional": "^15.0.0",
69
62
  "@neovici/eslint-config": "^1.3.0",
70
63
  "@open-wc/testing": "^2.5.0",
71
64
  "@polymer/iron-icon": "^3.0.1",
65
+ "@polymer/iron-icons": "^3.0.1",
72
66
  "@polymer/paper-button": "^3.0.0",
73
67
  "@polymer/paper-toggle-button": "^3.0.0",
74
- "@semantic-release/changelog": "^5.0.0",
75
- "@semantic-release/git": "^9.0.0",
76
- "@web/dev-server": "^0.1.17",
68
+ "@semantic-release/changelog": "^6.0.0",
69
+ "@semantic-release/git": "^10.0.0",
70
+ "@web/dev-server": "^0.1.0",
77
71
  "@web/test-runner": "^0.13.0",
78
72
  "@web/test-runner-selenium": "^0.5.0",
79
73
  "@webcomponents/webcomponentsjs": "^2.5.0",
80
- "eslint": "^7.0.0",
81
- "husky": "^6.0.0",
82
- "semantic-release": "^17.4.0",
83
- "sinon": "^11.0.0"
74
+ "husky": "^7.0.0",
75
+ "semantic-release": "^18.0.0",
76
+ "sinon": "^12.0.0"
84
77
  }
85
78
  }
@@ -1,62 +0,0 @@
1
- import {
2
- useEffect,
3
- useState,
4
- useMemo
5
- } from 'haunted';
6
- import { useViewInfo } from '@neovici/cosmoz-viewinfo';
7
-
8
- const useBottomBarView = ({
9
- active: initialActive = true,
10
- fixed
11
- }) => { /* eslint-disable no-return-assign */
12
- const { desktop } = useViewInfo(),
13
- isFixed = fixed ?? desktop,
14
- [active, setActive] = useState(initialActive),
15
- info = useMemo(() => ({}), []);
16
-
17
- useEffect(() => {
18
- if (isFixed) {
19
- return;
20
- }
21
- const
22
- { current: el } = info,
23
- opts = { passive: true },
24
- onScroll = () => {
25
- if (info.raf) {
26
- cancelAnimationFrame(info.raf);
27
- }
28
- info.raf = requestAnimationFrame(() => info.raf = requestAnimationFrame(() => {
29
- const { scrollTop } = el;
30
- setActive(
31
- scrollTop < 2 // at top
32
- || info.scrollTop > scrollTop // scrolling up
33
- || el.scrollHeight - scrollTop - el.offsetHeight < 3 // at bottom
34
- );
35
- Object.assign(info, {
36
- scrollTop,
37
- raf: undefined
38
- });
39
- }));
40
- };
41
- el.addEventListener('scroll', onScroll, opts);
42
- onScroll();
43
- return () => {
44
- el.removeEventListener('scroll', onScroll, opts);
45
- if (info.raf) {
46
- cancelAnimationFrame(info.raf);
47
- info.raf = undefined;
48
- }
49
- };
50
- }, [isFixed, info]);
51
-
52
- useEffect(() => {
53
- setActive(initialActive);
54
- }, [initialActive, setActive]);
55
-
56
- return {
57
- active,
58
- info
59
- };
60
- };
61
-
62
- export { useBottomBarView };