简体   繁体   English

如何阻止视图占用屏幕宽度并与 React Native 中的其他组件重叠?

[英]How do I stop a view from taking the screen's width and overlapping other components in React Native?

I'm trying to build a react native Note posting application where a user will press a button and a new note will be added to the screen.我正在尝试构建一个反应本机笔记发布应用程序,用户将按下按钮并将新笔记添加到屏幕中。 Each note has a title and a detail.每个注释都有一个标题和一个详细信息。 For now, they are being incremented.目前,它们正在增加。 So first time the user presses the button, a component with 'title 1' and 'detail 1' will be posted as a simple colored square.因此,当用户第一次按下按钮时,带有“title 1”和“detail 1”的组件将被发布为一个简单的彩色方块。 The problem now is, I want to be able to have a scroll-able view on the whole screen, and at the same time have a button locked on the screen on the bottom right corner that does not move even when we are scrolling through the application.现在的问题是,我希望能够在整个屏幕上有一个可滚动的视图,同时在右下角的屏幕上锁定一个按钮,即使我们滚动浏览应用。

An example of that is the Gmail app's Button for sending an email.一个例子是 Gmail 应用程序的按钮,用于发送 email。 Gmail Gmail

And this is my App, and the red Touchable opacity "Add Note."这是我的应用程序,红色的可触摸不透明度“添加注释”。 adds components.添加组件。

Before adding notes:添加注释之前:

Before adding添加前

After adding notes:添加注释后:

After adding添加后

How do I place the "Add Note."如何放置“添加注释”。 button at the right lower corner of the screen and lock it so that it doesn't move even when the components in FlatList Surpasses the screen.屏幕右下角的按钮并锁定它,这样即使 FlatList 中的组件超出屏幕,它也不会移动。

My Code:`我的代码:`

const IndexScreen = () => {
    const {state, addNote } = useContext(Context);
    return <View style={styles.Container}>
      <ScrollView>
          <FlatList
            data={state}
            keyExtractor={Note => Note.title}
            renderItem={({item}) => {
              return (item.note)
            }}
          />
          <TouchableOpacity style={styles.Note} onPress={addNote}>
            <Text>Add Note!</Text>
          </TouchableOpacity>
      </ScrollView>
    </View>
};

const styles = StyleSheet.create({
    Container: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        borderWidth : 2,
        borderColor: 'black',
    },
    Note: {
      height: 100,
      width: 100,
      borderWidth : 2,
      borderColor: 'yellow',
      alignSelf: 'flex-end',
      backgroundColor: 'red',
      flex: 1

    }
  });

` `

Not 100% sure, but you can try setting the position: absolute and then setting right and bottom properties too, so it then becomes fixed.不是 100% 确定,但您可以尝试设置position: absolute然后设置rightbottom属性,这样它就会变得固定。

How do I place the "Add Note!"如何放置“添加注释!” button at the right lower corner of the screen and lock it so that it doesn't move even when the components in FlatList Surpasses the screen屏幕右下角的按钮并锁定,这样即使FlatList中的组件超出屏幕也不会移动

You can use absolute positioning.您可以使用absolute定位。 Like this:像这样:

Note: {
  height: 100,
  width: 100,
  borderWidth : 2,
  borderColor: 'yellow',
  backgroundColor: 'red',
  position: "absolute",
  bottom: 0,
  right: 0
}

I added position , left and right properties.我添加了position right left

Try react-native-action-button.试试 react-native-action-button。 It will look great and at the same time your issue will be resolved.它看起来很棒,同时您的问题也将得到解决。 Here is the link .这是链接

react-native-floating-action should do the trick. react-native-floating-action应该可以解决问题。 https://www.npmjs.com/package/react-native-floating-action https://www.npmjs.com/package/react-native-floating-action

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM