2016-11-04 113 views
9

現狀如何在React Native中禁用圖像淡入效果?

  • 動態切換圖像
  • 陣營母語
  • 開發模式
  • 的Android

問題

  • 圖像在開發模式期間出現時會淡入。這是一個問題,因爲我正在開發和調整具有實際淡入效果的圖像動畫。是否可以禁用淡入效果?

嘗試

  • 切換到發佈模式。在開發過程中工作但不合適。
  • 最小化圖像文件大小。沒有明顯的差異。
  • 最小化圖像顯示大小。沒有明顯的差異。
+1

你可以發佈你正在使用 –

+0

一些代碼是否使用Animated.spring()在頁面的任何地方?我有一個問題,在視覺樹中的一個組件中使用它,意味着頁面上的每個元素都會獲得淡入淡出動畫。在我確定它來自哪裏之前,讓我有點瘋狂。 –

+0

你有沒有想過這個? –

回答

12

剛將fadeDuration={0}設置爲Image組件,這沒有記錄

您可以檢查here瞭解更多信息

+0

非常有用的答案。謝謝! – Val

0

我設法通過包裝我<Image />使用自定義ViewGroupManager和之前的圖像被添加到自定義ViewGroup與反思設置ReactImageView.mFadeDuration爲零,以防止褪色動畫。 編輯:但這顯示圖像時增加了一個明顯的延遲:(有實際上是沒有延遲

事情是這樣的:

public class NoFadeImageWrapper extends ViewGroup { 
    public NoFadeImageWrapper(Context context) { 
     super(context); 
    } 

    @Override 
    public void onViewAdded(View child) { 
     if (child instanceof ReactImageView) { 
      ((ReactImageView) child).setFadeDuration(0); 
      ReflectionUtils.setField(child, "mIsDirty", true); 
     } 
     super.onViewAdded(child); 
    } 
} 

ReflectionUtils.setField實現:

public class ReflectionUtils { 
    public static void setField(Object obj, String name, Object value) { 
     try { 
      Field field = getField(obj.getClass(), name); 
      if (field == null) { 
       return; 
      } 
      field.setAccessible(true); 
      field.set(obj, value); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
}