npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dioncodes/react-native-layout-margins

v1.3.3

Published

React Native Layout Margins

Downloads

6

Readme

react-native-layout-margins

A simple react native module for views that consider the iOS layoutMargins (including safe area insets). Supports two components for easy usage (<ContentInsetView /> and <ContentInsetFlatList />) and a method for querying the margins of the current root view.

Please read the iOS Layout Design Guides for more details on the layout margins.

Based on delightfulstudio/react-native-safe-area-insets.

Installation

yarn add @dioncodes/react-native-layout-margins
cd ios && pod install

Important: If you are updating from version 1.2 or earlier and using the components, you will need to add the LayoutMarginProvider (see Component Usage below).

Manual linking

  1. Open your project in XCode
  2. Add ./node_modules/@dioncodes/react-native-layout-margins/ios/RNLayoutMargins.xcodeproj to Libraries in your project
  3. Select root of your project
  4. Switch to General tab
  5. Scroll down to Linked Frameworks and Libraries section
  6. Click button +
  7. Add libRNLayoutMargins.a (if it's not present, build the project and try again)

Component Usage

To use the components you need to wrap your screens into a <LayoutMarginProvider>.

import { LayoutMarginProvider } from '@dioncodes/react-native-layout-margins';
...

const App = () => (
	<LayoutMarginProvider>
		...
	</LayoutMarginProvider>
);
import { ContentInsetView } from '@dioncodes/react-native-layout-margins';
...
<ContentInsetView>
	<Text>I'm aligned according to the iOS layout margins!</Text>
</ContentInsetView>
<ContentInsetView vertical horizontal>
	<Text>I'm aligned according to the iOS layout margins (including safe area), vertically and horizontally.</Text>
</ContentInsetView>
<ContentInsetView vertical>
	<Text>I'm vertically (but not horizontally) aligned according to the iOS layout margins (including safe area).</Text>
</ContentInsetView>

Also supporting a (react-native-gesture-handler) FlatList with content insets:

<ContentInsetFlatList
	data={...}
	renderItem={...}
	keyExtractor={(item) => item.id}
	vertical
	horizontal
/>

Props:

  • horizontal (boolean, optional)
  • vertical (boolean, optional)
  • top (boolean, optional)
  • left (boolean, optional)
  • right (boolean, optional)
  • bottom (boolean, optional)
  • style (optional ViewStyle prop that is passed to the View container)

ContentInsetFlatList also accepts all FlatList props.

If no property is set, only the horizontal padding is active.

Manual Usage With provider

import React from 'react';
import { View } from 'react-native';

import { useGetLayoutMarginProvider } from '@dioncodes/react-native-layout-margins';

export default function ExampleScreen() {
	const layoutMarginContext = useGetLayoutMarginProvider();
	const insets = layoutMarginContext.currentInsets;

	const insetStyle = {
		paddingLeft: insets.left,
		paddingRight: insets.right,
	};

	return (
		<View style={insetStyle}>
			<Text>I'm aligned according to the iOS layout margins!</Text>
		</View>
	);
}

Manual Usage Without Provider

import React, { useLayoutEffect, useState } from 'react';
import { View, Dimensions } from 'react-native';

import { currentInsets } from '@dioncodes/react-native-layout-margins';

export default function ExampleScreen() {
	const [insetStyle, setInsetStyle] = useState({ paddingLeft: 0, paddingRight: 0 });

	useLayoutEffect(() => {
		const setInsets = () => {
			currentInsets().then((insets) => {
				setInsetStyle({
					paddingLeft: insets.left,
					paddingRight: insets.right,
				});
			});
		};

		setInsets();
		Dimensions.addEventListener('change', setInsets);

		return function cleanup() {
			Dimensions.removeEventListener('change', setInsets);
		};
	}, []);


	return (
		<View style={insetStyle}>
			<Text>I'm aligned according to the iOS layout margins!</Text>
		</View>
	);
}