我试图加载自定义Android WebView,以便能够使用html文件输入上传文件(默认情况下,Android webview不能使用输入文件).我使用这个代码,唯一的区别是我使用expo工具包,所以我的MainApplication.java是不同的(默认情况下继承自另一个类):
public class MainApplication extends MultiDexApplication {
// Needed for `react-native link`
public List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new CustomWebViewPackage()
);
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
Run Code Online (Sandbox Code Playgroud)
基本上git代码所做的是覆盖默认的反应本机webview以使其使用Android中的CustomWebView.java,使用requireNativeComponent和此代码(这在CustomWebView.android.js上):
var RCTWebView = requireNativeComponent('CustomWebView', WebView, {
nativeOnly: {
messagingEnabled: PropTypes.bool,
},
Run Code Online (Sandbox Code Playgroud)
});
但是当我使用exp start运行应用程序并导航到具有CustomWebView的屏幕时,我收到此错误:
总结问题是React Native没有读取我的自定义本机组件.有谁可以帮助我吗?
我正在尝试将图像转换为 blob,以便将其上传到 aws s3 存储。在使用 expo-image-picker 选择图像后,我需要将图像转换为 blob,然后使用 fetch 转换为 blob,但它会导致以下错误。
错误 RangeError:无法构造“响应”:提供的状态 (0) 超出范围 [200, 599]。,js 引擎:hermes
这是我目前的情况:
import { Button, StyleSheet, Text, View } from 'react-native';
import * as ImagePicker from 'expo-image-picker'
export default function App() {
const PickImage = async()=>{
let result = await ImagePicker.launchImageLibraryAsync({
quality:1,
mediaTypes:ImagePicker.MediaTypeOptions.Images,
})
if(!result.canceled){
let response = await fetch(result.assets[0].uri);
let blob = await response.blob();
//code to upload image
}
}
return (
<View style={styles.container}>
<Button onPress={PickImage} title='TEST'/>
</View>
);
}
const styles …Run Code Online (Sandbox Code Playgroud)