Code Monkey home page Code Monkey logo

react-native-material-dialogs's Introduction

React Native Material Dialogs (Android)

Material Design Dialogs for React Native

[![npm version](https://badge.fury.io/js/react-native-material-dialogs.svg)](https://badge.fury.io/js/react-native-material-dialogs) [![GitHub stars](https://img.shields.io/github/stars/arjunkomath/react-native-material-dialogs.svg)](https://github.com/arjunkomath/react-native-material-dialogs/stargazers) [![Code Climate](https://codeclimate.com/github/arjunkomath/react-native-material-dialogs/badges/gpa.svg)](https://codeclimate.com/github/arjunkomath/react-native-material-dialogs)

Install

Install the npm module.

npm i react-native-material-dialogs

Plugin Installation (Android - Manual)

  • In your android/settings.gradle file, make the following additions:
include ':react-native-material-dialogs'
project(':react-native-material-dialogs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-material-dialogs')
  • In your android/build.gradle file, add the a maven repository:
...
repositories {
    ...
    maven { url "https://jitpack.io" }
}
  • In your android/app/build.gradle file, add the a compile-time dependency:
...
dependencies {
    ...
    compile project(':react-native-material-dialogs')
}
  • Next, you need to change the MainActivity of your app.
import com.arjunkomath.react.MaterialDialogPackage; // <--- Add This

...
/**
     * A list of packages used by the app. If the app uses additional views
     * or modules besides the default ones, add more packages here.
     */
    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
                new MaterialDialogPackage(this) // "this" is very important!
        );
    }

And, you're done!

Usage

import MaterialDialog from 'react-native-material-dialogs';

There are two types of dialogs:

Dialog with one feedback

MaterialDialog.show('Yaaay!!', 'Success', 'done', MaterialDialog.SUCCESS,
      () => {
        console.log('asd');
      });

Parameters:

MaterialDialog.show( <Title> , <Description>, <Button text>, <Type>, <Callback>);

Dialog with two feedbacks

MaterialDialog.showWithCancel('Danger!', 'Are you sure?', 'YES', 'NO', MaterialDialog.DANGER,
      () => {
        console.log('yes');
      },
      () => {
        console.log('no');
      });

Parameters:

MaterialDialog.show( <Title> , <Description>, <Positive Button text>, <Negative Button text>, <Type>, <Callback Positive>, <Callback Negative>);

Title, Description and Button text are of type String. While Type is a constant. There are four types:

MaterialDialog.SUCCESS
MaterialDialog.INFO
MaterialDialog.WARNING
MaterialDialog.DANGER

Example

import React, { Component } from 'react';
 import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TouchableOpacity
} from 'react-native';

import MaterialDialog from 'react-native-material-dialogs';

class dialog_test extends Component {

  press() {
    MaterialDialog.show('Yaaay!!', 'Success', 'done', MaterialDialog.SUCCESS,
      () => {
        console.log('done');
      });
  }

  render() {
    return (
      <View style={styles.container}>
      <TouchableOpacity onPress={this.press}>
      <Text style={styles.welcome}>
      Press me to see dialog!
      </Text>
      </TouchableOpacity>
      </View>
      );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  }
});

AppRegistry.registerComponent('dialog_test', () => dialog_test);

๐Ÿ’• Thanks

MaterialStyledDialogs

About Author

Built with <3 by Arjun Komath / [email protected]

react-native-material-dialogs's People

Contributors

arjunkomath avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.