All Projects → SrBrahma → react-native-shadow-2

SrBrahma / react-native-shadow-2

Licence: MIT license
Cross-platform shadow for React Native. Supports Android, iOS, Web and Expo.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-native-shadow-2

Shadowview
An iOS Library that makes shadows management easy on UIView.
Stars: ✭ 391 (-11.54%)
Mutual labels:  blur, shadow
Friendly Code Editor
Try this Friendly Code Editor. You'll love it. I made it with a lot of effort. It has some great features. I will update it adequately later. Very helpful for developers. Enjoy and share.
Stars: ✭ 20 (-95.48%)
Mutual labels:  blur
horse-wizard
Wizard for HORSE projects
Stars: ✭ 36 (-91.86%)
Mutual labels:  new
Auto Overnight
학교 외박신청 자동화 App Based in React Native
Stars: ✭ 12 (-97.29%)
Mutual labels:  expo
vue-image-shadow
🌈 A Vue image component. Simple realization of image shadow.
Stars: ✭ 21 (-95.25%)
Mutual labels:  shadow
ad-b2c-react-native
React Native Azure B2C Auth using pure js. This doesn't require eject from Expo.
Stars: ✭ 54 (-87.78%)
Mutual labels:  expo
expo-next-monorepo-example
Create a universal React app using Expo and Next.js in a monorepo
Stars: ✭ 268 (-39.37%)
Mutual labels:  expo
jellyfin-expo
Jellyfin Mobile for iOS
Stars: ✭ 164 (-62.9%)
Mutual labels:  expo
heylinda-app
The open source and free meditation app alternative for everyone. Built with React Native and Expo.
Stars: ✭ 481 (+8.82%)
Mutual labels:  expo
expo-rn-firebase-image-upload
example of how to upload image in expo with react-native and firebase
Stars: ✭ 47 (-89.37%)
Mutual labels:  expo
apple-notes
A clone of the Apple Notes app but made universally with Expo
Stars: ✭ 53 (-88.01%)
Mutual labels:  expo
ikuradon
Mastodon client app for React Native(Expo App)
Stars: ✭ 41 (-90.72%)
Mutual labels:  expo
chat-widget-native
Papercups chat widget for React Native/Expo
Stars: ✭ 24 (-94.57%)
Mutual labels:  expo
coronadev
Aplicativo para consultar a situação global do COVID-19
Stars: ✭ 44 (-90.05%)
Mutual labels:  expo
shadow
Shadow dom support for Vue
Stars: ✭ 46 (-89.59%)
Mutual labels:  shadow
eas-monorepo-example
Fast pnpm monorepo for cross-platform apps built with Expo / React Native and React.
Stars: ✭ 187 (-57.69%)
Mutual labels:  expo
app-monorepo
Secure, open source and community driven crypto wallet runs on all platforms and trusted by millions.
Stars: ✭ 1,282 (+190.05%)
Mutual labels:  expo
Vapecord-ACNL-Plugin
Animal Crossing NL Vapecord Public Plugin WIP
Stars: ✭ 72 (-83.71%)
Mutual labels:  new
proffy
React Native + ReactJS + NodeJS project developed on RocketSeat NexLevelWeek. This project is based on an application for connect students and teachers.
Stars: ✭ 30 (-93.21%)
Mutual labels:  expo
expo-deploy
Bash script to deploy to different Expo environments (https://expo.io)
Stars: ✭ 40 (-90.95%)
Mutual labels:  expo

npm TypeScript npm PRs Welcome

Buy Me A Coffee

⚠️ NOT CURRENTLY COMPATIBLE WITH [email protected]. use <=13.4.0 while the hotfix isn't released.

react-native-shadow-2

react-native-shadow is dead for years. This is an improved version with more functionalities, Typescript support and written from scratch. It's not required to define its size: the shadow is smartly applied on the first render and then precisely reapplied on the following ones.

It solves the old React Native issue of not having the same shadow appearence and usage for Android, iOS and Web.

The ethercreative/react-native-shadow-generator website won't give you very similar results between the two platforms, for the reasons I described here. It's also not as customizable as this library.

Compatible with Android, iOS and Web. And Expo!

Supports RTL.

🍟 Demo - Expo Snack Sandbox

Give this library a quick try!

📰 v7 Changelog - 2022-08-08

There are important breaking changes! Read it if upgrading!

↪️ Pre v7 Readme

Old Readme, if you are still using previous versions.

Read the FAQ below!

💿 Installation

1. First install react-native-svg.

The latest react-native-svg version is recommended, including if using Expo.

2. Then install react-native-shadow-2:

npm i react-native-shadow-2
# or
yarn add react-native-shadow-2

📖 Usage

import { Shadow } from 'react-native-shadow-2';

<Shadow>
  <Text style={{ margin: 20, fontSize: 20 }}>🙂</Text>
</Shadow>

Example 1


<Shadow distance={15} startColor={'#eb9066d8'} endColor={'#ff00ff10'} offset={[3, 4]}>
  <View style={{ borderTopStartRadius: 24, borderBottomEndRadius: 0, borderRadius: 10, backgroundColor: '#c454f0dd' }}>
    <Text style={{ margin: 20, fontSize: 20 }}>🤯</Text>
  </View>
</Shadow>

Example 2

Properties

All properties are optional.

Property Description Type Default
startColor The initial gradient color of the shadow. string '#00000020'
endColor The final gradient color of the shadow. string Transparent startColor. Explanation
distance How far the shadow goes. number 10
offset Moves the shadow. Negative x moves it left/start, negative y moves it up.

Accepts 'x%' values.

Defining this will default paintInside to true, as it's the usual desired behaviour.
[x: string | number, y: string | number] [0, 0]
paintInside Apply the shadow below/inside the content. startColor is used as fill color, without a gradient.

Useful when using offset or if your child has some transparency.
boolean false, but true if offset is defined
sides The sides that will have their shadows drawn. Doesn't include corners. Undefined sides fallbacks to true. Record<'left' | 'right' | 'top' | 'bottom', boolean> undefined
corners The corners that will have their shadows drawn. Undefined corners fallbacks to true. Record<'topStart' | 'topEnd' | 'bottomStart' | 'bottomEnd', boolean> undefined
style The style of the View that wraps your children. Read the Notes below. StyleProp<ViewStyle> undefined
containerStyle The style of the View that wraps the Shadow and your children. Useful for margins. StyleProp<ViewStyle> undefined
stretch Make your children ocuppy all available horizontal space. Explanation. boolean false
safeRender Won't use the relative sizing and positioning on the 1st render but on the following renders with the exact onLayout sizes. Useful if dealing with radii greater than the sides sizes (like a circle) to avoid visual artifacts on the 1st render.

If true, the Shadow won't appear on the 1st render.
boolean false
disabled Disables the Shadow. Useful for easily reusing components as sometimes shadows are not desired.

containerStyle and style are still applied.
boolean false

Notes

  • If the Shadow has a single child, it will get the width, height and all of the borderRadius properties from the children's style property, if defined.

  • You may also define those properties in the Shadow's style. The defined properties here will have priority over the ones defined in the child's style.

  • If the width and height are defined in any of those, there will be only a single render, as the first automatic sizing won't happen, only the precise render.

  • You can use either the 'borderTopLeftRadius' or 'borderTopStartRadius' and their variations to define the corners radii, although I recommend the latter as it's the RTL standard.

  • Having a radius greater than its side will mess the shadow if the sizes aren't defined. You can use the safeRender property to only show the shadow on the 2nd render and beyond, when we have the exact component size and the radii are properly limited.

⁉️ FAQ

  • How to set the Shadow opacity?

    The opacity is set directly in the startColor and endColor properties, in the alpha channel. E.g.: '#0001' is an almost transparent black. You may also use '#rrggbbaa', 'rgba()', 'hsla()' etc. All patterns in this link, but not int colors, are accepted.

  • My component is no longer using the available parent width after applying the Shadow! What to do?

    Use the stretch property or style={{alignSelf: 'stretch'}} in your Shadow component. Explanation!

  • I want a preset for my Shadows!

    It's exported the ShadowProps type, the props of the Shadow component. You may do the following:

    const ShadowPresets = {
      button: {
        offset: [0, 1], distance: 1, startColor: '#0003',
      } as ShadowProps,
    };
    
    <Shadow {...ShadowPresets.button}>
  • The offset and size properties are throwing Typescript errors!

    Upgrade your Typescript to at least 4.0.0! Those two properties use labeled tuples. If you don't use Typescript, this won't happen.

📰 Popularly seen on

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].