小编ser*_*tbh的帖子

Android:尝试使用 fetch 上传图像时网络请求失败

我正在尝试将图像从存储上传到一个安静的 API,但我在 Android 上不断收到网络请求失败(这意味着请求甚至没有通过),还没有在 iOS 上检查,因为我不需要那部分然而。API 已经在运行,并且已经用 Postman 进行了测试。

React Native 代码是:

  body.append('vehicles',{ 
    resource_id: 2,
    resource: 'vehicles',
    cat_file_id: fileId,
    active: 1,
    vehicles: photo, //<- photo value below
    name: 'vehicles',
    type: 'image/jpeg'
  })

  fetch(`${BASE_URL}/files`, {
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data',
      Accept: "*/*",
      Authorization: 'Bearer '+auth
    },
    body: body

  }).then(response => response.json())
  .then(response => {
    console.log('IMAGE RESPONSE', response)
  })
  .catch(error => console.log('ERROR', error))
Run Code Online (Sandbox Code Playgroud)

照片值看起来像 file:///storage/emulated/0/DCIM/...

响应:

ERROR TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (fetch.umd.js:473)
at XMLHttpRequest.dispatchEvent (event-target-shim.js:818)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:574)
at …
Run Code Online (Sandbox Code Playgroud)

react-native react-native-android

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

片段弹出堆栈动画不起作用

我想在打开和关闭时为片段设置动画。我有一个淡入和淡出自定义动画 XML 文件。

我在我的支持 FragmentTransaction 上使用 setCustomAnimations,但它所做的只是在我执行 addToBackStack 时进行动画处理,当我执行 popBackStack 时,它会在没有动画的情况下消失。

这是我的代码片段:

private void fragmentAppear(){
    fragment = new LoginFragment();
    fragmentManager = LoginActivity.this.getSupportFragmentManager();
    fragmentTransaction = fragmentManager.beginTransaction();
    //my XML anim files
    fragmentTransaction.setCustomAnimations(R.anim.slide_in_bottom,0,0,R.anim.slide_out_bottom);
    fragmentTransaction.replace(R.id.login_fragment, fragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

private void fragmentDisappear(){
    getSupportFragmentManager().popBackStack();
}
Run Code Online (Sandbox Code Playgroud)

在 setCustomAnimations 部分,我使用了 4 个参数,到目前为止,当我调用 fragmentAppear 时,它只在滑入之前显示淡出动画,但在调用 fragmentDisappear 时从不显示。我已经尝试过以许多不同的方式对参数进行排序,我也尝试过使用 setCustomAnimations 的两个参数版本,它所做的只是在片段出现时进行动画处理。

我正在为我的片段使用 android.support.v4.app 库。

编辑:此外,在不调用 fragmentDisappear 的情况下按下后退按钮时,动画也不会显示。

过去的代码在活动中,我试图从片段中执行 popBackStack 并且它也不起作用。这是关闭我的片段的正确方法吗?

编辑:我将包括 XML 动画:

slide_in_bottom.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromYDelta="75%p"
        android:toYDelta="0%p"
        android:fillAfter="true"
        android:duration="400" />
</set> …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-fragments

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