Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

[BUG]页面生命周期函数在start状态下能够正常调用,build后无法调用.Remax2.x #904

Closed
joesdu opened this issue May 7, 2020 · 4 comments · Fixed by #907
Labels
bug Something isn't working

Comments

@joesdu
Copy link

joesdu commented May 7, 2020

bug 描述
APP页面代码如上,使用start启动后,onShow函数会执行,使用build构建后,页面和APP生命周期函数均失效.

复现步骤
使用yarn start启动后,能够正常输出生命周期函数中的输出内容,使用build命令构建后,就无法正常工作了.

期望结果
生命周期函数正常工作.

复现代码

import './app.less';

import { getSystemInfo, getUpdateManager, onBeaconUpdate, setKeepScreenOn, showModal } from 'remax/wechat';
import React from 'react';

export const AppContext = React.createContext({});

export interface AppProps {
  location: any;
}
export interface Global {
  systemInfo?: WechatMiniprogram.GetSystemInfoSuccessCallbackResult;
}
interface AppState {
  global: Global;
}
class App extends React.Component<AppProps, AppState> {
  constructor(props: Readonly<AppProps>) {
    super(props);
    this.state = {
      global: { }
    };
  }

  setGlobal = (data: Global): void => {
    const { global } = this.state;
    this.setState({ global: { ...global, ...data } });
  };

  private checkUpgrade = () => {
    let updateManager: WechatMiniprogram.UpdateManager = getUpdateManager();
    updateManager.onCheckForUpdate((res: WechatMiniprogram.OnCheckForUpdateCallbackResult) => {
      if (res.hasUpdate) {
        updateManager.onUpdateReady(() => {
          showModal({
            title: '更新提示',
            content: '新版本已经准备好,是否重启应用进行更新?',
            success: (res: WechatMiniprogram.ShowModalSuccessCallbackResult) => {
              if (res.confirm) updateManager.applyUpdate();
            }
          });
        });
        updateManager.onUpdateFailed(() =>
          showModal({
            title: '已经有新版本了哟~',
            content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
          })
        );
      }
    });
  };

  componentDidMount = () => {
    getSystemInfo()
      .then((res: WechatMiniprogram.GetSystemInfoSuccessCallbackResult) => {
        this.setGlobal({ systemInfo: res });
        const { locationAuthorized, bluetoothEnabled, locationEnabled } = res;
        if (!locationAuthorized || !bluetoothEnabled || !locationEnabled) {
          this.setGlobal({ hadFail: true });
        } else this.SearchIBeacon();
      })
      .catch((error: any) => console.error(error));
    setKeepScreenOn({ keepScreenOn: true });
    this.checkUpgrade();
  };

  onShow = (): void => console.log('AppOnShow');

  // onShow = (): void => {
  //   console.log('AppOnShow');
  //   getSystemInfo()
  //     .then((res: WechatMiniprogram.GetSystemInfoSuccessCallbackResult) => {
  //       this.setGlobal({ systemInfo: res });
  //       const { locationAuthorized, bluetoothEnabled, locationEnabled } = res;
  //       if (!locationAuthorized || !bluetoothEnabled || !locationEnabled) {
  //         TODO 
  //       } else this.SearchIBeacon();
  //     })
  //     .catch((error: any) => console.error(error));
  //   setKeepScreenOn({ keepScreenOn: true });
  //   this.checkUpgrade();
  // };

  render() {
    const { global } = this.state;
    const { setGlobal } = this;
    return <AppContext.Provider value={{ global, setGlobal }}>{this.props.children}</AppContext.Provider>;
  }
}
export default App;

版本信息:

  • remax 版本: [e.g. 2.0.1]
  • 手机型号 [e.g. iPhone X]
  • 小程序端 [e.g. 微信小程序]
  • 小程序版本[e.g. 2.3.0]
  • 开发环境 [e.g. Windows OS]

其他信息
[如截图等其他信息可以贴在这里]

@joesdu joesdu added the bug Something isn't working label May 7, 2020
@joesdu joesdu changed the title [BUG]页面生命周期函数在start状态下能够正常调用,build后无法调用. [BUG]页面生命周期函数在start状态下能够正常调用,build后无法调用.Remax2.x May 7, 2020
@Darmody
Copy link
Contributor

Darmody commented May 7, 2020

没法复现,能不能提供一个demo

@joesdu
Copy link
Author

joesdu commented May 7, 2020

没法复现,能不能提供一个demo

你可以看一下 https://github.com/joesdu/remax-bug-issue

这个图是start后,控制台输出的信息.
image

这个是build后控制台输出的信息,
image

可以看到welcome 的 onShow输出没了.

@Darmody
Copy link
Contributor

Darmody commented May 8, 2020

@joesdu 感谢提供复现 demo。问题已修复

@joesdu
Copy link
Author

joesdu commented May 8, 2020

@joesdu 感谢提供复现 demo。问题已修复
这个问题我觉得还是提供个新版本吧,不然现在版本只能依靠start后的文件进行提交,包会很大.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants