Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to customize reactnative view dropshadow

//https://reactnative.dev/docs/shadow-props
import React, { useState } from "react";
import { Text, View, StyleSheet, Slider } from "react-native";

const ShadowPropSlider = ({ label, value, ...props }) => {
  return (
    <>
      <Text>
        {label} ({value.toFixed(2)})
      </Text>
      <Slider step={1} value={value} {...props} />
    </>
  );
}

const App = () => {
  const [shadowOffsetWidth, setShadowOffsetWidth] = useState(0);
  const [shadowOffsetHeight, setShadowOffsetHeight] = useState(0);
  const [shadowRadius, setShadowRadius] = useState(0);
  const [shadowOpacity, setShadowOpacity] = useState(0.1);

  return (
    <View style={styles.container}>
      <View
        style={[
          styles.square,
          {
            shadowOffset: {
              width: shadowOffsetWidth,
              height: -shadowOffsetHeight
            },
            shadowOpacity,
            shadowRadius
          }
        ]}
      />
      <View style={styles.controls}>
        <ShadowPropSlider
          label="shadowOffset - X"
          minimumValue={-50}
          maximumValue={50}
          value={shadowOffsetWidth}
          onValueChange={val => setShadowOffsetWidth(val)}
        />
        <ShadowPropSlider
          label="shadowOffset - Y"
          minimumValue={-50}
          maximumValue={50}
          value={shadowOffsetHeight}
          onValueChange={val => setShadowOffsetHeight(val)}
        />
        <ShadowPropSlider
          label="shadowRadius"
          minimumValue={0}
          maximumValue={100}
          value={shadowRadius}
          onValueChange={val => setShadowRadius(val)}
        />
        <ShadowPropSlider
          label="shadowOpacity"
          minimumValue={0}
          maximumValue={1}
          step={0.05}
          value={shadowOpacity}
          onValueChange={val => setShadowOpacity(val)}
        />
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "space-around",
    backgroundColor: "#ecf0f1",
    padding: 8
  },
  square: {
    alignSelf: "center",
    backgroundColor: "white",
    borderRadius: 4,
    height: 150,
    shadowColor: "black",
    width: 150
  },
  controls: {
    paddingHorizontal: 12
  }
});

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: Block Alignment Toolbar Using ES5 in Wordpress 
Javascript :: Paginate array in JavaScript 
Javascript :: Array helper functions in ES6 
Javascript :: default parameters in es6 
Javascript :: blur area behind an element in react native 
Javascript :: ngFor fake 
Javascript :: what does react js allows us to do 
Javascript :: async await slow down code 
Javascript :: Node Red to their W1HQ station 
Javascript :: set value 
Javascript :: all files website checker 
Javascript :: mdn javascript console.log(Math.random()); 
Javascript :: discord-buttons collector 
Javascript :: define nasty 
Javascript :: console form elememts as json object 
Javascript :: json mapper 
Javascript :: CalendarTriggerBuilder 
Javascript :: Pass File and JSON Data Both at Same time in Postman API 
Javascript :: react 1 to 10 rating 
Javascript :: moment js formating to one day less using zulu time 
Javascript :: ceil function js but 1.1 as 2 
Javascript :: javascript to prevent method POST from realoading 
Javascript :: how to filter data in javascript object 
Javascript :: form validation jflutter 
Javascript :: c# adding a root node to a json object 
Javascript :: convert milliseconds to hours minutes seconds javascript 
Javascript :: check if date is valid js 
Javascript :: convert js to typescript online 
Javascript :: check if string is json parsable 
Javascript :: reduce example 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =