我对Expo和React-Native的机制,它们如何下载资产感到困惑。
我知道的信息是,一旦您构建代码,expo就会准备一个捆绑包,其中同时包含javascript(编译后的代码)和资产。
并且在调试会话期间,该捆绑包-整体上-首先由expo客户端下载,然后启动该应用程序。这意味着一旦启动应用程序,代码中所有“导入”的资产都应就位。
另一方面,当我运行以下原子测试代码时,这是完全相反的。加载这些资产需要花费时间,就像它们是“延迟加载”一样。
所以我的问题是;行为开发模式相关吗?还是在生产模式下下载图像仍然需要时间?
import * as React from 'react';
import { Text, View, StyleSheet, Image, Button } from 'react-native';
import Test0Img from './assets/test0.gif';
import Test1Img from './assets/test1.gif';
export default class App extends React.Component {
constructor() {
super();
this.state = {
imageIndex: 0,
};
}
render() {
return (
<View style={styles.container}>
<Text></Text>
<Text></Text>
<Button
onPress={() => {
let l_newImageIndex = (this.state.imageIndex + 1) % 2;
this.setState({ imageIndex: l_newImageIndex });
}}
title="Click to Change Image"
/>
<Image
source={this.state.imageIndex …Run Code Online (Sandbox Code Playgroud) 似乎 WebView 在 react-native 中扮演着类似 web 工作者的角色。
我试图卸载大量数据取到的WebView但它似乎很痛苦,找不到一个fetch有例子WebView。
所以我有下面的 JavaScript 代码,我试图用它来调用 API。
当使用来自常规 react-native 类的完全相同的代码时,JSON 响应被完美地获取和解析。
但是当相同的 JavaScript 代码被注入到带有injectJavaScript方法的 WebView 中时,该Content-Type值会导致问题。(当我删除它时,我从后端看到进行了调用,但我无法在前端获取 JSON 数据 - WebView 端 -。)
尽管 API 后端允许所有跨域请求,但它似乎与 cors 相关。
因此,我的问题是:
var l_headers = {
Accept: 'application/json',
'Content-Type': 'application/json'
};
var l_init = {
method: "POST",
headers: l_headers,
body: {}
};
fetch("http://172.20.10.12:8000/test", l_init).then(function (response) {
return response.json();
}).then(function …Run Code Online (Sandbox Code Playgroud) 我的问题是关于在react和/或react-native动画中使用translateX和translateY,以将对象设置为动画。
这两个变换使对象相对于现有点移动。
但是对于这种情况,现有坐标并不重要,我想确保将对象移动到屏幕上可能存在的任何点。
附加的限制是,我不能动画的风格top,bottom,left并right因为在反应本地的,如果我们这些动画风格那么我们不能使用useNativeDriver={true}这会导致性能问题指令。
我正在调查是否可以在移动设备上设置“网络套接字服务器”(与“后端的网络套接字服务器”的常见方法不同)。
为了做到这一点,我正在为 iOS 和 Android 设备寻找一种方法来接受 WebSocket 请求。
旁注,我不太确定移动操作系统的安全设计是否允许。
有没有办法在移动设备上设置网络套接字服务器?(如果是,更进一步,是否有任何方法可以与 react-native 一起使用?)
我有以下package.json文件。主要目的是将 Expo 44 与 native-base (版本 )一起使用^3.0.0。我不明白为什么这样一个明显的组合不起作用。(网上找不到native-base,也推荐使用Expo版本。)
package.json:
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject",
"test": "node ./node_modules/jest/bin/jest.js --watchAll"
},
"dependencies": {
"@expo/samples": "2.1.1",
"@expo/vector-icons": "^12.0.0",
"@react-native-async-storage/async-storage": "~1.15.0",
"@react-native-community/datetimepicker": "4.0.0",
"@react-native-community/netinfo": "7.1.3",
"@react-native-picker/picker": "2.2.1",
"expo": "^44.0.0",
"expo-ads-admob": "~12.0.0",
"expo-app-loading": "~1.3.0",
"expo-apple-authentication": "~4.1.0",
"expo-application": "~4.0.1",
"expo-asset": "~8.4.5",
"expo-auth-session": "~3.5.0",
"expo-av": "~10.2.0",
"expo-facebook": "~12.1.0",
"expo-font": "~10.0.4",
"expo-haptics": "~11.1.0",
"expo-image-manipulator": "~10.2.0",
"expo-random": "~12.1.1",
"expo-screen-orientation": "~4.1.1",
"expo-sharing": …Run Code Online (Sandbox Code Playgroud) 我试图找到如何调试react-native-web应用程序(特别是使用Expo和vscode)。
我既没有在网络上也没有在react-native-web自己的网站上找到指导。
React Native Tools附带的调试配置旨在在 Expo 应用程序中运行,但我的目的是使用浏览器来调试/测试 React-Native-Web 行为。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug in Exponent",
"request": "launch",
"type": "reactnative",
"cwd": "${workspaceFolder}",
"platform": "exponent",
"expoHostType": "local"
}
]
}
Run Code Online (Sandbox Code Playgroud) react-native react-native-web expo react-native-debugger react-native-tools
我正在尝试将react-spring动画库导入基于react组件类的reactjs应用程序。
似乎新的(截至2019年)React Hooks使集成变得更加混乱。
所以这就是为什么我问如何react-spring在ReactJS应用程序中使用哪些使用类,进而使用React钩子的原因。
无法正常工作的代码如下所示:
import React from 'react';
import { useSpring, animated, interpolate } from 'react-spring'
export default class TestAnimation extends React.Component {
constructor(props) {
super(props);
const { o, xyz, color } = useSpring({
from: { o: 0, xyz: [0, 0, 0], color: 'red' },
o: 1,
xyz: [10, 20, 5],
color: 'green'
});
this.aniText = <animated.div
style={{
// If you can, use plain animated values like always, ...
// You would do that in …Run Code Online (Sandbox Code Playgroud) react-native ×6
expo ×3
reactjs ×2
android ×1
fetch ×1
ios ×1
native-base ×1
npm ×1
react-hooks ×1
react-spring ×1
websocket ×1
webview ×1