@tarojs/router 4.0.0-beta.3 → 4.0.0-beta.31

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.
package/dist/api.js CHANGED
@@ -46,6 +46,21 @@ function navigate(option, method) {
46
46
  if ('url' in option) {
47
47
  const pathPieces = processNavigateUrl(option);
48
48
  const state = { timestamp: Date.now() };
49
+ if (pathPieces.pathname) {
50
+ const originPath = routesAlias.getOrigin(pathPieces.pathname);
51
+ const pagePath = originPath.startsWith('/') ? originPath.substring(1) : originPath;
52
+ if (!RouterConfig.pages.includes(pagePath)) {
53
+ const res = { errMsg: `${method}:fail page ${pagePath} is not found` };
54
+ fail === null || fail === void 0 ? void 0 : fail(res);
55
+ complete === null || complete === void 0 ? void 0 : complete(res);
56
+ if (fail || complete) {
57
+ return resolve(res);
58
+ }
59
+ else {
60
+ return reject(res);
61
+ }
62
+ }
63
+ }
49
64
  if (method === 'navigateTo') {
50
65
  history.push(pathPieces, state);
51
66
  }
@@ -71,7 +86,12 @@ function navigate(option, method) {
71
86
  const res = { errMsg: `${method}:fail ${error.message || error}` };
72
87
  fail === null || fail === void 0 ? void 0 : fail(res);
73
88
  complete === null || complete === void 0 ? void 0 : complete(res);
74
- reject(res);
89
+ if (fail || complete) {
90
+ return resolve(res);
91
+ }
92
+ else {
93
+ return reject(res);
94
+ }
75
95
  }
76
96
  });
77
97
  });
@@ -2,12 +2,18 @@ let pageResizeFn;
2
2
  function bindPageResize(page) {
3
3
  pageResizeFn && window.removeEventListener('resize', pageResizeFn);
4
4
  pageResizeFn = function () {
5
- page.onResize && page.onResize({
6
- size: {
7
- windowHeight: window.innerHeight,
8
- windowWidth: window.innerWidth
9
- }
10
- });
5
+ if (page.onResize) {
6
+ const mediaQuery = window.matchMedia('(orientation: portrait)');
7
+ page.onResize({
8
+ deviceOrientation: mediaQuery.matches ? 'portrait' : 'landscape',
9
+ size: {
10
+ windowHeight: window.innerHeight,
11
+ windowWidth: window.innerWidth,
12
+ screenHeight: window.screen.height,
13
+ screenWidth: window.screen.width,
14
+ }
15
+ });
16
+ }
11
17
  };
12
18
  window.addEventListener('resize', pageResizeFn, false);
13
19
  }
package/dist/history.js CHANGED
@@ -32,7 +32,7 @@ class MpaHistory {
32
32
  url += `?${to.search}`;
33
33
  }
34
34
  if (to.hash) {
35
- url += `#${to.hash}`;
35
+ url += to.hash.startsWith('#') ? to.hash : `#${to.hash}`;
36
36
  }
37
37
  return url;
38
38
  }
@@ -54,7 +54,12 @@ declare class RoutesAlias {
54
54
  declare const routesAlias: RoutesAlias;
55
55
  declare const isWeixin: () => boolean;
56
56
  declare const isDingTalk: () => boolean;
57
- declare function setTitle(title: string): Promise<string>;
57
+ declare function setMpaTitle(title: string): void;
58
+ declare function setTitle(title: string): void;
59
+ declare function setNavigationBarStyle(option: {
60
+ backgroundColor: string;
61
+ frontColor: string;
62
+ }): void;
58
63
  declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
59
64
  declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
60
- export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setTitle, handleAppMount, handleAppMountWithTabbar };
65
+ export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, handleAppMount, handleAppMountWithTabbar };
package/dist/index.cjs.js CHANGED
@@ -8,6 +8,32 @@ var history = require('history');
8
8
  var queryString = require('query-string');
9
9
  var UniversalRouter = require('universal-router');
10
10
 
11
+ const home_svg_str = `
12
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
13
+ <path d="M23.8899 12.2737C23.8232 12.3584 23.7237 12.3997 23.6198 12.3974H20.7994V23.5996C20.7994 23.8194 20.6213 24 20.4001 24H14.7994C14.5791 24 14.4002 23.8194 14.4002 23.5996V15.6H9.59963V23.5996C9.59963 23.8194 9.42075 24 9.20033 24H3.59968C3.48981 24 3.38964 23.954 3.31764 23.8811C3.24495 23.8091 3.2004 23.7087 3.2004 23.5996V12.3975H0.398546V12.3967C0.296893 12.396 0.194446 12.3544 0.11579 12.2738C-0.0371146 12.114 -0.0400714 11.864 0.11579 11.7076L11.7201 0.117284C11.8767 -0.0390948 12.1298 -0.0390948 12.2863 0.117284L23.8899 11.7076C24.0465 11.864 24.0265 12.0995 23.8899 12.2737ZM12.0029 0.964625L1.37086 11.5854L3.59968 11.5839V11.5999C3.65537 11.5999 3.70804 11.611 3.75557 11.6307C3.89952 11.692 4.00046 11.8339 4.00046 11.9996V23.1991H8.79955V15.2003C8.79955 14.9789 8.97917 14.8002 9.20033 14.8002H14.7995C15.0207 14.8002 15.2003 14.9789 15.2003 15.2003V23.1991H20.0001V11.9996C20.0001 11.8339 20.1003 11.692 20.2443 11.6307C20.2918 11.611 20.3453 11.5999 20.4001 11.5999V11.5713L22.6193 11.5691L12.0029 0.964625Z" fill="currentColor"/>
14
+ </svg>
15
+ `;
16
+ const back_svg_str = `
17
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
18
+ <path d="M17.8206 22.9016L7.45515 11.8756L17.8206 1.09845C18.0598 0.849741 18.0598 0.435233 17.8206 0.186528C17.5814 -0.0621762 17.1827 -0.0621762 16.9435 0.186528L6.1794 11.4611C5.9402 11.7098 5.9402 12.1244 6.1794 12.3731L16.9435 23.8135C17.1827 24.0622 17.5814 24.0622 17.8206 23.8135C18.0598 23.5648 18.0598 23.1503 17.8206 22.9016Z" fill="currentColor"/>
19
+ </svg>
20
+
21
+ `;
22
+ function initNavigationBar(container) {
23
+ const navigationBar = document.createElement('taro-navigation-bar-wrap');
24
+ navigationBar.classList.add('taro-navigation-bar-no-icon');
25
+ const navigationBarBackBtn = document.createElement('taro-navigation-bar-back');
26
+ const navigationBarHomeBtn = document.createElement('taro-navigation-bar-home');
27
+ navigationBarBackBtn.innerHTML = back_svg_str;
28
+ navigationBarHomeBtn.innerHTML = home_svg_str;
29
+ const navigationBarTitle = document.createElement('taro-navigation-bar-title');
30
+ navigationBar.appendChild(navigationBarHomeBtn);
31
+ navigationBar.appendChild(navigationBarBackBtn);
32
+ navigationBar.appendChild(navigationBarTitle);
33
+ navigationBar.id = 'taro-navigation-bar';
34
+ container.prepend(navigationBar);
35
+ }
36
+
11
37
  function initTabbar(config, history) {
12
38
  if (config.tabBar == null || config.tabBar.custom) {
13
39
  return;
@@ -88,7 +114,7 @@ class MpaHistory {
88
114
  url += `?${to.search}`;
89
115
  }
90
116
  if (to.hash) {
91
- url += `#${to.hash}`;
117
+ url += to.hash.startsWith('#') ? to.hash : `#${to.hash}`;
92
118
  }
93
119
  return url;
94
120
  }
@@ -245,26 +271,29 @@ class Stacks {
245
271
  }
246
272
  const stacks = new Stacks();
247
273
 
248
- let preTitle = document.title;
249
- let isLoadDdEntry = false;
250
274
  const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
251
275
  const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
252
- function setTitle(title) {
253
- return tslib.__awaiter(this, void 0, void 0, function* () {
254
- if (preTitle === title)
255
- return title;
256
- document.title = title;
257
- preTitle = title;
258
- if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
259
- if (!isLoadDdEntry) {
260
- isLoadDdEntry = true;
261
- require('dingtalk-jsapi/platform');
262
- }
263
- const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
264
- setDingTitle({ title });
276
+ let preTitle = document.title;
277
+ let isLoadDdEntry = false;
278
+ function setMpaTitle(title) {
279
+ if (preTitle === title)
280
+ return;
281
+ document.title = title;
282
+ preTitle = title;
283
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
284
+ if (!isLoadDdEntry) {
285
+ isLoadDdEntry = true;
286
+ require('dingtalk-jsapi/platform');
265
287
  }
266
- return title;
267
- });
288
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
289
+ setDingTitle({ title });
290
+ }
291
+ }
292
+ function setTitle(title) {
293
+ runtime.eventCenter.trigger('__taroH5SetNavigationTitle', title);
294
+ }
295
+ function setNavigationBarStyle(option) {
296
+ runtime.eventCenter.trigger('__taroH5setNavigationBarColor', option);
268
297
  }
269
298
 
270
299
  class RoutesAlias {
@@ -348,6 +377,21 @@ function navigate(option, method) {
348
377
  if ('url' in option) {
349
378
  const pathPieces = processNavigateUrl(option);
350
379
  const state = { timestamp: Date.now() };
380
+ if (pathPieces.pathname) {
381
+ const originPath = routesAlias.getOrigin(pathPieces.pathname);
382
+ const pagePath = originPath.startsWith('/') ? originPath.substring(1) : originPath;
383
+ if (!RouterConfig.pages.includes(pagePath)) {
384
+ const res = { errMsg: `${method}:fail page ${pagePath} is not found` };
385
+ fail === null || fail === void 0 ? void 0 : fail(res);
386
+ complete === null || complete === void 0 ? void 0 : complete(res);
387
+ if (fail || complete) {
388
+ return resolve(res);
389
+ }
390
+ else {
391
+ return reject(res);
392
+ }
393
+ }
394
+ }
351
395
  if (method === 'navigateTo') {
352
396
  exports.history.push(pathPieces, state);
353
397
  }
@@ -373,7 +417,12 @@ function navigate(option, method) {
373
417
  const res = { errMsg: `${method}:fail ${error.message || error}` };
374
418
  fail === null || fail === void 0 ? void 0 : fail(res);
375
419
  complete === null || complete === void 0 ? void 0 : complete(res);
376
- reject(res);
420
+ if (fail || complete) {
421
+ return resolve(res);
422
+ }
423
+ else {
424
+ return reject(res);
425
+ }
377
426
  }
378
427
  });
379
428
  });
@@ -408,12 +457,18 @@ let pageResizeFn;
408
457
  function bindPageResize(page) {
409
458
  pageResizeFn && window.removeEventListener('resize', pageResizeFn);
410
459
  pageResizeFn = function () {
411
- page.onResize && page.onResize({
412
- size: {
413
- windowHeight: window.innerHeight,
414
- windowWidth: window.innerWidth
415
- }
416
- });
460
+ if (page.onResize) {
461
+ const mediaQuery = window.matchMedia('(orientation: portrait)');
462
+ page.onResize({
463
+ deviceOrientation: mediaQuery.matches ? 'portrait' : 'landscape',
464
+ size: {
465
+ windowHeight: window.innerHeight,
466
+ windowWidth: window.innerWidth,
467
+ screenHeight: window.screen.height,
468
+ screenWidth: window.screen.width,
469
+ }
470
+ });
471
+ }
417
472
  };
418
473
  window.addEventListener('resize', pageResizeFn, false);
419
474
  }
@@ -457,6 +512,9 @@ function getOffset() {
457
512
  */
458
513
  function loadAnimateStyle(ms = 300) {
459
514
  const css = `
515
+ body {
516
+ overflow: hidden; // 防止 iOS 页面滚动
517
+ }
460
518
  .taro_router > .taro_page {
461
519
  position: absolute;
462
520
  left: 0;
@@ -518,6 +576,60 @@ ${enableTabBar ? `
518
576
  `;
519
577
  addStyle(css);
520
578
  }
579
+ /**
580
+ * 插入导航栏相关的样式
581
+ */
582
+ function loadNavigationBarStyle() {
583
+ const css = `
584
+ .taro-navigation-bar-show {
585
+ background: white;
586
+ position: sticky;
587
+ z-index: 500;
588
+ top: 0;
589
+ padding-bottom: 8px;
590
+ padding-top: calc(env(safe-area-inset-top) + 8px);
591
+ display: flex;
592
+ justify-content: center;
593
+ align-items: center;
594
+ }
595
+
596
+ .taro-navigation-bar-hide {
597
+ display: none;
598
+ }
599
+
600
+ taro-navigation-bar-title {
601
+ font-size: 24px;
602
+ height: 24px;
603
+ line-height: 24px;
604
+ }
605
+
606
+ .taro-navigation-bar-no-icon > taro-navigation-bar-home {
607
+ display: none;
608
+ }
609
+
610
+ .taro-navigation-bar-no-icon > taro-navigation-bar-back {
611
+ display: none;
612
+ }
613
+
614
+ .taro-navigation-bar-home > taro-navigation-bar-home {
615
+ display: block;
616
+ left: 8px;
617
+ position: absolute;
618
+ width: 24px;
619
+ height: 24px;
620
+ }
621
+
622
+ .taro-navigation-bar-back > taro-navigation-bar-back {
623
+ display: block;
624
+ left: 8px;
625
+ position: absolute;
626
+ width: 24px;
627
+ height: 24px;
628
+ }
629
+
630
+ `;
631
+ addStyle(css);
632
+ }
521
633
  function addStyle(css) {
522
634
  if (!css)
523
635
  return;
@@ -686,6 +798,7 @@ function createMultiRouter(history, app, config, framework) {
686
798
  if (typeof app.onUnhandledRejection === 'function') {
687
799
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
688
800
  }
801
+ runtime.eventCenter.on('__taroH5SetNavigationTitle', setMpaTitle);
689
802
  RouterConfig.config = config;
690
803
  const handler = new MultiPageHandler(config, history);
691
804
  const launchParam = {
@@ -719,7 +832,7 @@ function createMultiRouter(history, app, config, framework) {
719
832
  return;
720
833
  let enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
721
834
  if (pageConfig) {
722
- setTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
835
+ setMpaTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
723
836
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
724
837
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
725
838
  }
@@ -731,9 +844,219 @@ function createMultiRouter(history, app, config, framework) {
731
844
  const page = runtime.createPageConfig(enablePullDownRefresh ? runtime.hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + runtime.stringify(launchParam), {}, loadConfig);
732
845
  handler.load(page, pageConfig);
733
846
  (_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
847
+ window.addEventListener('visibilitychange', () => {
848
+ var _a, _b;
849
+ if (document.visibilityState === 'visible') {
850
+ (_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
851
+ }
852
+ else {
853
+ (_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
854
+ }
855
+ });
734
856
  });
735
857
  }
736
858
 
859
+ class NavigationBarHandler {
860
+ constructor(pageContext) {
861
+ this.isLoadDdEntry = false;
862
+ this.cache = {};
863
+ this.pageContext = pageContext;
864
+ this.init();
865
+ loadNavigationBarStyle();
866
+ runtime.eventCenter.on('__taroH5SetNavigationTitle', (title) => {
867
+ this.setTitle(title);
868
+ });
869
+ runtime.eventCenter.on('__taroH5setNavigationBarColor', ({ backgroundColor, frontColor }) => {
870
+ if (typeof backgroundColor === 'string')
871
+ this.setNavigationBarBackground(backgroundColor);
872
+ if (typeof frontColor === 'string')
873
+ this.setNavigationBarTextStyle(frontColor);
874
+ });
875
+ }
876
+ toHomeFn() {
877
+ reLaunch({ url: this.pageContext.homePage });
878
+ }
879
+ backFn() {
880
+ navigateBack();
881
+ }
882
+ get homeBtnElement() {
883
+ var _a;
884
+ if (!this.navigationBarElement)
885
+ return null;
886
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-home')) === null || _a === void 0 ? void 0 : _a[0];
887
+ }
888
+ get backBtnElement() {
889
+ var _a;
890
+ if (!this.navigationBarElement)
891
+ return null;
892
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-back')) === null || _a === void 0 ? void 0 : _a[0];
893
+ }
894
+ get titleElement() {
895
+ var _a;
896
+ if (!this.navigationBarElement)
897
+ return null;
898
+ return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-title')) === null || _a === void 0 ? void 0 : _a[0];
899
+ }
900
+ init() {
901
+ var _a, _b;
902
+ this.setNavigationBarElement();
903
+ if (!this.navigationBarElement)
904
+ return;
905
+ (_a = this.homeBtnElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.toHomeFn.bind(this));
906
+ (_b = this.backBtnElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.backFn.bind(this));
907
+ }
908
+ setNavigationBarElement() {
909
+ var _a;
910
+ this.navigationBarElement = (_a = document.getElementsByTagName('taro-navigation-bar-wrap')) === null || _a === void 0 ? void 0 : _a[0];
911
+ }
912
+ load() {
913
+ this.setCacheValue();
914
+ this.setTitle();
915
+ this.setNavigationBarVisible();
916
+ this.setFnBtnState();
917
+ this.setNavigationBarBackground();
918
+ this.setNavigationBarTextStyle();
919
+ }
920
+ setCacheValue() {
921
+ const currentPage = this.pageContext.currentPage;
922
+ if (typeof this.cache[currentPage] !== 'object') {
923
+ this.cache[currentPage] = {};
924
+ }
925
+ }
926
+ setFnBtnState() {
927
+ const currentRouter = this.pageContext.currentPage;
928
+ if (this.pageContext.isTabBar(currentRouter) || this.pageContext.homePage === currentRouter) {
929
+ this.fnBtnToggleToNone();
930
+ }
931
+ else if (stacks.length > 1) {
932
+ this.fnBtnToggleToBack();
933
+ }
934
+ else {
935
+ this.fnBtnToggleToHome();
936
+ }
937
+ }
938
+ setNavigationBarBackground(backgroundColor) {
939
+ var _a, _b, _c;
940
+ if (!this.navigationBarElement)
941
+ return;
942
+ const currentPage = this.pageContext.currentPage;
943
+ let color;
944
+ if (typeof backgroundColor === 'string') {
945
+ color = backgroundColor;
946
+ this.cache[currentPage] &&
947
+ (this.cache[currentPage].backgroundColor = color);
948
+ }
949
+ else {
950
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.backgroundColor;
951
+ if (typeof cacheValue === 'string') {
952
+ color = cacheValue;
953
+ }
954
+ else {
955
+ color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarBackgroundColor) || '#000000';
956
+ this.cache[currentPage] &&
957
+ (this.cache[currentPage].backgroundColor = color);
958
+ }
959
+ }
960
+ this.navigationBarElement.style.background = color;
961
+ }
962
+ setNavigationBarTextStyle(fontColor) {
963
+ var _a, _b, _c;
964
+ if (!this.navigationBarElement)
965
+ return;
966
+ const currentPage = this.pageContext.currentPage;
967
+ let color;
968
+ if (typeof fontColor === 'string') {
969
+ color = fontColor;
970
+ this.cache[currentPage] &&
971
+ (this.cache[currentPage].fontColor = color);
972
+ }
973
+ else {
974
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.fontColor;
975
+ if (typeof cacheValue === 'string') {
976
+ color = cacheValue;
977
+ }
978
+ else {
979
+ color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarTextStyle) || 'white';
980
+ this.cache[currentPage] &&
981
+ (this.cache[currentPage].fontColor = color);
982
+ }
983
+ }
984
+ this.navigationBarElement.style.color = color;
985
+ }
986
+ setTitle(title) {
987
+ var _a, _b, _c;
988
+ const currentPage = this.pageContext.currentPage;
989
+ let proceedTitle;
990
+ if (typeof title === 'string') {
991
+ proceedTitle = title;
992
+ this.cache[currentPage] &&
993
+ (this.cache[currentPage].title = proceedTitle);
994
+ }
995
+ else {
996
+ const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.title;
997
+ if (typeof cacheValue === 'string') {
998
+ proceedTitle = cacheValue;
999
+ }
1000
+ else {
1001
+ proceedTitle = (_c = (_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationBarTitleText) !== null && _c !== void 0 ? _c : document.title;
1002
+ this.cache[currentPage] &&
1003
+ (this.cache[currentPage].title = proceedTitle);
1004
+ }
1005
+ }
1006
+ if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
1007
+ if (!this.isLoadDdEntry) {
1008
+ this.isLoadDdEntry = true;
1009
+ require('dingtalk-jsapi/platform');
1010
+ }
1011
+ const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
1012
+ setDingTitle({ proceedTitle });
1013
+ }
1014
+ document.title = proceedTitle;
1015
+ if (!this.titleElement)
1016
+ return;
1017
+ this.titleElement.innerHTML = proceedTitle;
1018
+ }
1019
+ fnBtnToggleToHome() {
1020
+ if (!this.navigationBarElement)
1021
+ return;
1022
+ this.navigationBarElement.classList.add('taro-navigation-bar-home');
1023
+ this.navigationBarElement.classList.remove('taro-navigation-bar-back');
1024
+ }
1025
+ fnBtnToggleToBack() {
1026
+ if (!this.navigationBarElement)
1027
+ return;
1028
+ this.navigationBarElement.classList.remove('taro-navigation-bar-home');
1029
+ this.navigationBarElement.classList.add('taro-navigation-bar-back');
1030
+ }
1031
+ fnBtnToggleToNone() {
1032
+ if (!this.navigationBarElement)
1033
+ return;
1034
+ this.navigationBarElement.classList.remove('taro-navigation-bar-home');
1035
+ this.navigationBarElement.classList.remove('taro-navigation-bar-back');
1036
+ }
1037
+ setNavigationBarVisible(show) {
1038
+ var _a, _b;
1039
+ let shouldShow;
1040
+ if (typeof show === 'boolean') {
1041
+ shouldShow = show;
1042
+ }
1043
+ else {
1044
+ shouldShow = (_a = this.pageContext.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
1045
+ if (typeof ((_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
1046
+ shouldShow = this.pageContext.pageConfig.navigationStyle;
1047
+ }
1048
+ }
1049
+ if (shouldShow === 'default') {
1050
+ this.navigationBarElement.classList.add('taro-navigation-bar-show');
1051
+ this.navigationBarElement.classList.remove('taro-navigation-bar-hide');
1052
+ }
1053
+ else {
1054
+ this.navigationBarElement.classList.add('taro-navigation-bar-hide');
1055
+ this.navigationBarElement.classList.remove('taro-navigation-bar-show');
1056
+ }
1057
+ }
1058
+ }
1059
+
737
1060
  /* eslint-disable dot-notation */
738
1061
  class PageHandler {
739
1062
  constructor(config, history) {
@@ -742,6 +1065,7 @@ class PageHandler {
742
1065
  this.config = config;
743
1066
  this.homePage = runtime.getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
744
1067
  this.mount();
1068
+ this.navigationBarHandler = new NavigationBarHandler(this);
745
1069
  }
746
1070
  get currentPage() {
747
1071
  const routePath = runtime.getCurrentPage(this.routerMode, this.basename);
@@ -885,6 +1209,7 @@ class PageHandler {
885
1209
  this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
886
1210
  this.addAnimation(pageEl, pageNo === 0);
887
1211
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1212
+ this.navigationBarHandler.load();
888
1213
  this.bindPageEvents(page, pageConfig);
889
1214
  this.triggerRouterChange();
890
1215
  }
@@ -897,6 +1222,7 @@ class PageHandler {
897
1222
  this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
898
1223
  this.addAnimation(pageEl, pageNo === 0);
899
1224
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1225
+ this.navigationBarHandler.load();
900
1226
  this.onReady(page, true);
901
1227
  this.bindPageEvents(page, pageConfig);
902
1228
  this.triggerRouterChange();
@@ -951,6 +1277,7 @@ class PageHandler {
951
1277
  pageEl.classList.remove('taro_page_shade');
952
1278
  this.addAnimation(pageEl, pageNo === 0);
953
1279
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1280
+ this.navigationBarHandler.load();
954
1281
  this.bindPageEvents(page, pageConfig);
955
1282
  this.triggerRouterChange();
956
1283
  }
@@ -960,6 +1287,7 @@ class PageHandler {
960
1287
  pageEl = this.getPageContainer(page);
961
1288
  this.addAnimation(pageEl, pageNo === 0);
962
1289
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1290
+ this.navigationBarHandler.load();
963
1291
  this.onReady(page, false);
964
1292
  this.bindPageEvents(page, pageConfig);
965
1293
  this.triggerRouterChange();
@@ -1076,7 +1404,7 @@ function createRouter(history$1, app, config, framework) {
1076
1404
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1077
1405
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1078
1406
  const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
1079
- var _c, _d, _e, _f, _g, _h, _j, _k, _l;
1407
+ var _c, _d, _e, _f, _g, _h, _j, _k;
1080
1408
  handler.pathname = decodeURI(location.pathname);
1081
1409
  if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1082
1410
  window.scrollTo(0, 0);
@@ -1116,7 +1444,6 @@ function createRouter(history$1, app, config, framework) {
1116
1444
  let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
1117
1445
  let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
1118
1446
  if (pageConfig) {
1119
- setTitle((_j = pageConfig.navigationBarTitleText) !== null && _j !== void 0 ? _j : document.title);
1120
1447
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1121
1448
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
1122
1449
  }
@@ -1133,7 +1460,7 @@ function createRouter(history$1, app, config, framework) {
1133
1460
  runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1134
1461
  const currentPage = runtime.Current.page;
1135
1462
  const pathname = handler.pathname;
1136
- const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
1463
+ const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1137
1464
  const cacheTabs = stacks.getTabs();
1138
1465
  let shouldLoad = false;
1139
1466
  stacks.method = '';
@@ -1199,7 +1526,7 @@ function createRouter(history$1, app, config, framework) {
1199
1526
  shouldLoad = true;
1200
1527
  }
1201
1528
  if (shouldLoad || stacks.length < 1) {
1202
- const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
1529
+ const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
1203
1530
  const loadConfig = Object.assign({}, pageConfig);
1204
1531
  const stacksIndex = stacks.length;
1205
1532
  delete loadConfig['path'];
@@ -1224,6 +1551,15 @@ function createRouter(history$1, app, config, framework) {
1224
1551
  }
1225
1552
  render({ location: history$1.location, action: history.Action.Push });
1226
1553
  (_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
1554
+ window.addEventListener('visibilitychange', () => {
1555
+ var _a, _b;
1556
+ if (document.visibilityState === 'visible') {
1557
+ (_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1558
+ }
1559
+ else {
1560
+ (_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
1561
+ }
1562
+ });
1227
1563
  return history$1.listen(render);
1228
1564
  }
1229
1565
 
@@ -1239,6 +1575,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
1239
1575
  app.classList.add('taro_router');
1240
1576
  if (!isPosition)
1241
1577
  appWrapper.appendChild(app);
1578
+ initNavigationBar(appWrapper);
1242
1579
  }
1243
1580
  function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
1244
1581
  let app = document.getElementById(appId);
@@ -1264,6 +1601,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
1264
1601
  appWrapper.replaceChild(container, app);
1265
1602
  }
1266
1603
  initTabbar(config, history);
1604
+ initNavigationBar(container);
1267
1605
  }
1268
1606
 
1269
1607
  Object.defineProperty(exports, 'createBrowserHistory', {
@@ -1290,5 +1628,7 @@ exports.redirectTo = redirectTo;
1290
1628
  exports.routesAlias = routesAlias;
1291
1629
  exports.setHistory = setHistory;
1292
1630
  exports.setHistoryMode = setHistoryMode;
1631
+ exports.setMpaTitle = setMpaTitle;
1632
+ exports.setNavigationBarStyle = setNavigationBarStyle;
1293
1633
  exports.setTitle = setTitle;
1294
1634
  exports.switchTab = switchTab;
@@ -54,7 +54,12 @@ declare class RoutesAlias {
54
54
  declare const routesAlias: RoutesAlias;
55
55
  declare const isWeixin: () => boolean;
56
56
  declare const isDingTalk: () => boolean;
57
- declare function setTitle(title: string): Promise<string>;
57
+ declare function setMpaTitle(title: string): void;
58
+ declare function setTitle(title: string): void;
59
+ declare function setNavigationBarStyle(option: {
60
+ backgroundColor: string;
61
+ frontColor: string;
62
+ }): void;
58
63
  declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
59
64
  declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
60
- export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setTitle, handleAppMount, handleAppMountWithTabbar };
65
+ export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, handleAppMount, handleAppMountWithTabbar };