React Native Blank Spacer đĻâī¸đĻ
Free your components from margins using the blank spacer!!Build Statusbuild-badgebuild !Maintainabilitymaintainability-badgemaintainability-url !Test Coveragecoverage-badgecoverage-url
!Versionversion-badgepackage !Downloadsdownloads-badgenpmtrends !Bundlephobiabundle-phobia-badgebundle-phobia
!Star on GitHubgithub-star-badgegithub-star !Watch on GitHubgithub-watch-badgegithub-watch !Twitter Followtwitter-badgetwitter
Compatible with Expo & React Native Web đ
PRs Welcome đâ¨
- đĄ Why use blank spacer?
- đĻ Installation
- âšī¸ Usage
- đ Recipes
Why use blank spacer
A good component should be usable in any layout & context. This means the component should not influence anything outside of it's own children.Margins however break this rule by defining how much space another component should distance itself from your component. This has made many components difficult to use in certain layouts and also made maintaining the design system very difficult in the long run for my personal projects.
Max Stoiber has written a nice blog post on why we shouldn't use margins and move to spacers.
React Native Blank Spacer is component which can be used to apply blank spaces between components effectively removing the need to apply margins in general đ
Installation
#npm
npm install --save react-native-blank-spacer
#yarn
yarn add react-native-blank-spacer
Usage
import BlankSpacer from "react-native-blank-spacer";
const App = () => (
<View>
<Text>Hello!</Text>
<BlankSpacer height={16} />
<Text>Nice to Meet you!</Text>
<View>
);
export default App;
Props
height?: number
Height of the blank spacerwidth?: number
Width of the blank spacer īšŖ used to apply space when flexDirection: row
color?: color string
Color of the blank spacerViewProps
All the existing View props are supported as blank spacer extends the view componentRecipes
- Follow the link to the snack for Simple Usage
- If you want to apply spacing based on the device screen size, you can use the blank spacer with react-native-responsive-dimensions
- If you want a blank space to avoid keyboard (i.e) a keyboard avoiding view, you can use react-native-keyboad-spacer or pair the blank spacer with keyboard height received from
useKeyboard
hook of react native hooks