8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RN(expo)でグラデーション。カード風エリアを作る。

Posted at

 やりたいこと

  • カード風エリアを作りたい
  • 背景をグラデーションにしたい
  • クリッカブルにしたい

完成品

グラーデーションつけて、ちょっと影落として(難あり)、クリッカブルにする。

準備

グラデーションは標準では難しいらしいので専用のモジュールを利用します。
私はexpoを利用しているのですが、そのまま使えるモジュールがあるようなので、それを利用してみます。

npm install --save expo-linear-gradient

実装

App.js
import React from 'react';
import { View, Button, Text, TouchableHighlight } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';

export default class BlackFade extends React.Component {
    render() {
        return (
            <View style={{ flex: 1, alignItems: 'center', paddingTop: 60 }}>
                <TouchableHighlight
                    onPress={() => console.log("hoge")}
                    underlayColor="#fff"
                    activeOpacity={0.7}
                    style={{
                        shadowColor: "#000",
                        shadowOffset: { width: 1, height: 1 },
                        shadowRadius: 1,
                        shadowOpacity:0.3 //影は無くてもいいかな・・・
                    }}
                >
                    <LinearGradient
                        colors={['#393FFF', '#44A5FF']}
                        start={{ x: 0, y: 0 }}
                        end={{ x: 1, y: 1 }}
                        style={{
                            height: 200,
                            width: 320,
                            borderRadius: 10,
                        }}
                    >
                        <Text
                            style={{
                                color: "#fff",
                                position: "absolute",
                                top: 40,
                                left: 50,
                                fontSize: 20,
                            }}
                        >
                            1234-5678-9012-3456
                        </Text>
                    </LinearGradient>
                </TouchableHighlight>
            </View>
        );
    }
}
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?