亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React Native - 動畫僅在Android上的Toggle Inspect之后工作

React Native - 動畫僅在Android上的Toggle Inspect之后工作

蝴蝶刀刀 2022-09-02 10:39:30
我對 React/React-Native 環境很陌生,在 Android 上動畫方面遇到了一些問題。我正在使用反應動畫來顯示底部的錯誤和警告警報。問題是動畫在iOS上工作正常,但只有在我啟用“切換檢查器”后才能在Android上運行,如果我不啟用它,動畫就不起作用,在調試器上,我能夠看到組件在React組件結構上。我已經嘗試了解決方法,將Anifeed.Value設置為0.01并將Animale.createAnimatedComponent更改為Anidient.View。動畫應該在狀態更改并且可見屬性設置為TRUE之后發生,狀態的更改是可以的,因為我可以看到它在React Native Debbuger上工作,并且slideIn / slideOut函數正在被useEffect鉤子調用。我使用的是 React 16.11.0 和 React-Native 0.62.2 版本更新我從組件中刪除了位置:絕對值,現在我能夠在屏幕頂部看到動畫,我嘗試將z索引的值更改為更高的值(我的應用程序中沒有任何高于1的z索引),但它不起作用。以下是代碼的主要部分:export const Alert = withTheme(({ theme: { primary, textGray } }) => {  const translateValue = useRef(new Animated.Value(0)).current;  const dispatch = useDispatch();  const {    visible,    data: { type, message }  } = useSelector(({ notification }) => notification);  const slideIn = useCallback(() => {    Animated.timing(translateValue, {      toValue: 1,      duration: 1000,      useNativeDriver: true    }).start();  }, [translateValue]);  const slideOut = useCallback(() => {    Animated.timing(translateValue, {      toValue: 0,      duration: 1000,      useNativeDriver: true    }).start();  }, [translateValue]);  const handleClose = () => {    dispatch(hideNotification());  };  useEffect(() => {    if (visible) {      slideIn();    } else {      slideOut();    }  }, [visible, slideIn, slideOut]);  return (    <Wrapper      style={{        transform: [          {            translateY: translateValue.interpolate({              inputRange: [0, 1],              outputRange: [300, 0]            })          }        ]      }}>      <Content>        <Icon name={icons[type]} size={20} color={primary} />        <Message>{message}</Message>      </Content>      <Button        onPress={handleClose}        accessible        accessibilityRole="button"        accessibilityLabel="Fechar notifica??o">        <Icon size={20} name="x" color={textGray} />      </Button>    </Wrapper>  );});
查看完整描述

1 回答

?
哆啦的時光機

TA貢獻1779條經驗 獲得超6個贊

固定!Android上的z索引似乎存在一些問題。為了解決這個問題,我剛剛添加了海拔高度:當平臺是Android時為1。


請參閱下面的代碼:


    <Wrapper

          isAndroid={Platform.OS === 'android'}

          style={{

            transform: [

              {

                translateY: translateValue.interpolate({

                  inputRange: [0, 1],

                  outputRange: [300, 0]

                })

              }

            ]

          }}>

          <Content>

            <Icon name={icons[type]} size={20} color={primary} />

            <Message>{message}</Message>

          </Content>

          <Button

            onPress={handleClose}

            accessible

            accessibilityRole="button"

            accessibilityLabel="Fechar notifica??o">

            <Icon size={20} name="x" color={textGray} />

          </Button>

        </Wrapper>

      );


    const Wrapper = Animated.createAnimatedComponent(styled.SafeAreaView`

      width: 100%;

      border-top-width: 1px;

      border-top-color: ${({ theme: { border } }) => border};

      background: ${({ theme: { background } }) => background};

      z-index: 1;

      position: absolute;

      flex-direction: row;

      justify-content: space-between;

      align-items: center;

      bottom: 0;

      left: 0;

      ${({ isAndroid }) => isAndroid && 'elevation: 1'}

    `);


查看完整回答
反對 回復 2022-09-02
  • 1 回答
  • 0 關注
  • 115 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號