簡體   English   中英

如何讓我的 ScrollView 不回彈到頂部? (反應原生)

[英]How do I keep my ScrollView from snapping back to the top? (React Native)

為了創建一個可滾動的 UI,我決定使用 ScrollView 來顯示我的所有組件。 但是,每當我嘗試滾動到底部時,只要松開手指,應用程序就會彈回頂部。 我嘗試向 ScrollView 及其父視圖添加樣式,但它似乎對我的情況沒有幫助。

這是我的代碼:

export default function App() {

  const items = [
    <TopText key='1' />,
    <Bar key='2' />,
    <TabDivider key='3' type="Carpool" />,
    <Tiles key='4' />,
    <TabDivider key='5' type="Schedule" />,
    <Schedule key='6' />]

  return (
    <View style={styles.container}>
      <ScrollView style={styles.scrollViewStyle}>
        {items}
      </ScrollView>

      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    position: 'relative',
    flex: 1,
    backgroundColor: 'rgba(187, 248, 237, 0.41)',
  },

  scrollViewStyle: {
    position: 'absolute',
    top: 0,
    bottom: 0,
    left: 0,
    right: 0,
  }
});

如果您能幫助我,我將不勝感激:D

我想到了! 我要做的就是將 ScrollView 包裹在視圖周圍,然后編輯樣式。 這是更新的代碼:

export default function App() {

  return (
      <ScrollView>
        <View style={styles.container}>
          <TopText key='1' />
          <Bar key='2' />
          <TabDivider key='3' type="Carpool" />
          <Tiles key='4' />
          <TabDivider key='5' type="Schedule" />
          <Schedule key='6' />
          
          <StatusBar style='auto'/>
        </View>
      </ScrollView>



  );
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: 'rgba(187, 248, 237, 0.41)',
    height: 2000
  }
});


暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM