小编Ash*_*n M的帖子

如何通过设备锁定屏幕冷启动React Native应用程序?

我正在React Native上构建VoIP应用程序,该应用程序使用推送通知检测来电。我需要启动应用程序,并在收到推送通知时将其置于前台。我能够在以下情况下实现:

  1. 解锁设备后:
    • 该应用程序已最小化(仍在后台)
    • 该应用程序不在后台(从多任务视图中删除)
  2. 设备锁定时:
    • 该应用程序已最小化(仍在后台)

我无法处理的唯一情况是设备被锁定并且应用被杀死时。该应用程序启动,但未显示在锁定屏幕上。相反,用户需要解锁手机才能访问应用程序。

这是收到通知时运行的代码,

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    Intent notificationIntent = new Intent(this, MainActivity.class);
    // Check if app is running

    if(MainActivity.isAppRunning) {
        startActivity(notificationIntent);
        Intent messagingEvent = new Intent(MESSAGE_EVENT);
        messagingEvent.putExtra("message", remoteMessage);
        // Broadcast it so it is only available to the RN Application
        LocalBroadcastManager
                .getInstance(this)
                .sendBroadcast(messagingEvent);
    } else {
        startActivity(notificationIntent);
        try {
            // If the app is in the background we send it to the Headless JS Service
            Intent headlessIntent = new Intent(
                    this.getApplicationContext(), …
Run Code Online (Sandbox Code Playgroud)

java android react-native react-native-android react-native-navigation

8
推荐指数
1
解决办法
619
查看次数

禁用提升时,如何将 React 库从一个 Yarn 工作区导入到另一个 Yarn 工作区?

我正在使用 Yarn v2 (berry) 来管理具有以下结构的 monorepo:

project-root
  /packages
    react-native-app
      (dependencies: my-hooks-lib, react@17.0.1)
    my-hooks-lib
      (dependency: react@17.0.1)
Run Code Online (Sandbox Code Playgroud)

这是我的 .yarnrc.yml:

yarnPath: ".yarn/releases/yarn-berry.cjs"
nodeLinker: "node-modules"
nmHoistingLimits: "workspaces"
Run Code Online (Sandbox Code Playgroud)

自从我使用 React Native 应用程序以来,我已经禁用了提升。但正因为如此,react-native-app并且my-hooks-lib有单独的副本react@17.0.1,即使版本相同。这会导致Invalid Hooks call错误:

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You …
Run Code Online (Sandbox Code Playgroud)

reactjs react-native yarnpkg yarn-workspaces yarnpkg-v2

7
推荐指数
0
解决办法
931
查看次数

如何在我的主项目中使用React Native中的Storybook?

我有一个React Native项目设置使用,react-native init并且正在使用Storybook隔离开发我的组件。我getstorybook在该项目中运行了该命令,然后CLI生成了一个storybook包含所有必需文件的目录,如Storybook docs中所述
当我运行npm run storybookcommand后跟时react-native run-android,我可以在模拟器上查看故事。现在,如果我需要运行我的主要应用程序(而非传奇故事,但是这是由所产生的一个react-native init命令),我要运行npm run start之后react-native run-android
每当我从Storybook切换到主应用程序时,是否有不必不必构建应用程序的方法?我在这里错过明显的东西吗?
提前致谢!

android react-native storybook

6
推荐指数
0
解决办法
280
查看次数

CSS"玻璃阴影"效果

我正在尝试实现这种阴影效果,其中阴影就像图像本身的模糊版本:

在此输入图像描述

我能够通过将相同的图像堆叠两次并应用于下面的图像来实现它filter: blur(20px),但这感觉就像一种低效的方式:

.cover-wrapper {
  position: relative;
  margin: 50px;
  width: 200px;
  height: 200px;
}

.cover {
  z-index: 1;
  border-radius: 10px;
  position: absolute;
  width: 200px;
  height: 200px;
}

.cover-shadow-wrapper {
  position: absolute;
  filter: blur(20px);
  overflow: hidden;
  height: 200px;
  width: 200px;
}

.cover-shadow {
  transform: scale(1.5)
}
Run Code Online (Sandbox Code Playgroud)
<div class="cover-wrapper">
  <img src="https://picsum.photos/200/200?image=871" alt="cover" class="cover">  
  <div class="cover-shadow-wrapper">
    <img src="https://picsum.photos/200/200?image=871" alt="shadow" class="cover-shadow">
  </div>    
</div>
Run Code Online (Sandbox Code Playgroud)

有更有效的方法吗?此外,这个效果实际上叫什么?

html css

5
推荐指数
1
解决办法
278
查看次数

Android Emulator无法在Ubuntu 16.10上运行

我使用Acer Aspire E1-530搭配Intel 2117U处理器和6GB RAM.

我按照React Native网站中给出的步骤安装了React Native和Android Studio 2.3,并且还按照此Ubuntu文档中的说明安装了KVM .Android Studio启动没有问题,我成功地设置了AVD,但是当我启动AVD时,一个小窗口显示一小段时间然后消失.我也试过运行emulator~/Android/Sdk/tools,但它显示了这个错误:

libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing
libGL error: failed to load driver: i965
libGL error: unable to load driver: swrast_dri.so
libGL error: failed to load driver: swrast
X Error of failed request:  GLXBadContext
  Major opcode …
Run Code Online (Sandbox Code Playgroud)

ubuntu android-emulator android-studio react-native ubuntu-16.04

4
推荐指数
1
解决办法
1428
查看次数

使用react-router渲染404页面来反应PWA:create-react-app

仅当我将PWA添加到主屏幕并从那里运行应用程序时才会发生这种情况.当我在移动或桌面浏览器上运行应用程序时,我没有看到这种行为.

我正在使用create-react-app构建的React应用程序.运行npm run build并使用任何本地http服务器提供后,它工作正常.一旦我将其部署到Firebase或now在Firefox或Chrome移动浏览器上打开网站,它似乎也能正常工作.但是,当我点击弹出窗口中的"添加到主屏幕"按钮时,它会被添加,但是从主屏幕图标打开它会呈现404路线.

<Switch/>如果没有路径匹配URL,我使用react-router的组件路由到自定义404页面.以下是我定义路由器"配置"的方法:

<Router>
    <Switch>
      <Route exact path="/" component={Login} />
      <Route path="/login" component={Login} />
      <Route path="/sign-up" component={SignUp} />
      <Route 
        render={() => (
        <div>
          <h1>Error 404: Not Found</h1>
          <Link to="/">Go Home</Link>
        </div>)}
      />
    </Switch>
</Router>
Run Code Online (Sandbox Code Playgroud)

我的软件包版本package.json:

  • react:^ 16.2.0
  • react-scripts:1.1.0
  • react-router-dom:^ 4.2.2

javascript reactjs react-router progressive-web-apps create-react-app

4
推荐指数
1
解决办法
1861
查看次数

如何在带有 Vite 的 Web Worker 中使用 JSX?

我正在使用@remote-ui/react库在 Web Worker 中呈现我的 React 代码。我在项目中使用 Vite,但每当我尝试在工作脚本中使用 JSX 时,我都会看到以下错误:

Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong. See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201
Run Code Online (Sandbox Code Playgroud)

在这里创建了一个最小的复制品。

reactjs vite

0
推荐指数
2
解决办法
4484
查看次数