美文网首页
2022-04-25 react-native获取刘海屏的高度

2022-04-25 react-native获取刘海屏的高度

作者: 无尽甜蜜里悠悠记忆 | 来源:发表于2022-04-25 16:42 被阅读0次

android和ios都支持

import Reactfrom 'react';

import { StyleSheet, Text, View }from 'react-native';

import {getDefaultHeaderHeight }from '@react-navigation/elements';

import {

useSafeAreaFrame,

  useSafeAreaInsets,

}from 'react-native-safe-area-context';

const styles = StyleSheet.create({

container: {

flex:1,

  },

});

function HomePage() {

const frame =useSafeAreaFrame();

  const insets =useSafeAreaInsets();

  const headerHeight =getDefaultHeaderHeight(frame, false, insets.top);

  console.log('headerHeight=>', headerHeight);

  return (

<View style={[styles.container, {marginTop: headerHeight /2 }]}>

      <Text>主页面{headerHeight}

  );

}

export default HomePage;

相关文章

网友评论

      本文标题:2022-04-25 react-native获取刘海屏的高度

      本文链接:https://www.haomeiwen.com/subject/uhzfyrtx.html