0.0.3 • Published 7 years ago

react-native-android-function v0.0.3

Weekly downloads
2
License
Apache License 2....
Repository
github
Last release
7 years ago

React Native: react-native-android-function

GitHub package version npm home platforms github home npm

github issues github closed issues Issue Stats github license

📖 Getting started

$ npm install react-native-android-function --save

$ react-native link react-native-android-function

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.zappi.android.function.AndroidFunctionPackage; to the imports at the top of the file
  • Add new AndroidFunctionPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-android-function'
    project(':react-native-android-function').projectDir = new File(rootProject.projectDir,'../node_modules/react-native-android-function/android/app')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-android-function')

💻 Usage

import AndroidFunction from 'react-native-android-function';

Intents

Youtube

AndroidFunction.Youtube(url);
PropTypeDefaultNote
urlstringURL of the Youtube video to open.
fullscreenbooleantrueIt allows you to choose whether to view the video in fullscreen mode.
AndroidFunction.Youtube(url,fullscreen);
PropTypeDefaultNote
urlstringURL of the YouTube video to open.
fullscreenbooleanIt allows you to choose whether to view the video in fullscreen mode.

Facebook

AndroidFunction.Facebook(id);
PropTypeDefaultNote
idstringId of Facebook profile to open.

Instagram

AndroidFunction.Instagram(id);
PropTypeDefaultNote
idstringId of Instagram profile to open.

Twitter

AndroidFunction.Twitter(id);
PropTypeDefaultNote
idstringId of Twitter profile to open.

Google Play Store

AndroidFunction.GooglePlayStore(id);
PropTypeDefaultNote
idstringId of Google Play Store profile to open.
AndroidFunction.GooglePlayStore();

Open as intent the google play store passing id in the app in use it is on the google play store.

General intent

AndroidFunction.General(appIntent,setPackage,webIntent);
PropTypeDefaultNote
appIntentstring
setPackagestring
webIntentstring
AndroidFunction.ShortCuts(urlImg,cropped,shortLabel,longLabel,appUri,setPackage);
PropTypeDefaultNote
urlImgstringUrl of the image.
croppedbooleanAbility of skill the rounding of the image.
shortLabelstring
longLabelstring
appUristring
setPackagestring
AndroidFunction.ShortCutsType(urlImg,cropped,shortLabel,longLabel,type,id);
PropTypeDefaultNote
urlImgstringUrl of the image.
croppedbooleanAbility of skill the rounding of the image.
shortLabelstring
longLabelstring
typestringWhat kind of intent to use: facebook,instagram,twitter,googleplaystore
idstringid of the user to pass

Pinned ShortCuts

import * as React from 'react';
import { Text, View, StyleSheet, ToastAndroid } from 'react-native';
import AndroidFunction from 'react-native-android-function';

AndroidFunction.pinnedShortcuts.setShortcutItems([
  {
    typeImg: 'icon',
    icon: {
      family: 'Entypo',
      name: 'browser',
      colorIcon: '#90a4ae',
      colorCircle: '#000000',
    },
    shortLabel: 'Browser',
    longLabel: 'Open Browser',
    typeIntent: 'uri',
    appUri: 'https://www.google.com/',
  },
  {
    typeImg: 'url',
    urlImg:
      'http://images.amcnetworks.com/bbcamerica.com/wp-content/uploads/2017/05/anglo_2000x1125_larapulver-e1495023889751-640x360.jpg',
    shortLabel: 'Pulver',
    longLabel: 'Lara Pulver',
    typeIntent: 'uri',
    appUri: 'https://twitter.com/larapulver',
    setPackage: 'com.twitter.android',
  },
  {
    typeImg: 'letter',
    colorText: '#ffffff',
    colorCircle: '#e57373',
    shortLabel: 'Watson',
    longLabel: 'Emma Watson',
    typeIntent: 'uri',
    appUri: 'https://www.instagram.com/_u/emmawatson/',
    setPackage: 'com.instagram.android',
  },
  {
    typeImg: 'icon',
    icon: {
      family: 'MaterialCommunityIcons',
      name: 'emoticon-happy',
    },
    shortLabel: 'App pass param',
    longLabel: 'Open App',
    typeIntent: 'app',
    infoIntent: {
      name: 'Megan',
      surname: 'Fox',
      urlImg:
        'https://scontent-mxp1-1.cdninstagram.com/vp/3c4732c2cd3566727dad10f03c04b7bd/5C9241C4/t51.2885-19/s150x150/34706107_1875460276079648_8096847319644766208_n.jpg',
      age: 32,
      height: '1.63 m',
    },
  },
]);

export default class ExampleShortcuts extends React.Component {
  constructor() {
    super();
    this.state = {
      data: {},
    };
  }

  componentDidMount() {
    AndroidFunction.pinnedShortcuts
      .popInitialAction()
      .then(data => {
        if (Object.keys(data).length == 0 || Object.keys(data.obj).length == 0)
          return;
        console.log('App3:', data);
        this.setState({ data: data.obj });
        ToastAndroid.show(data.obj.name, ToastAndroid.SHORT);
      })
      .catch(console.error);
  }

  render() {
    const { data } = this.state;
    return (
      <View style={styles.container}>
      <Text style={styles.paragraph}>Quick Action: {(data.name && data.name+" "+data.surname) || 'None'}</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  paragraph: {
    margin: 24,
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'center',
  },
});

AndroidFunction.pinnedShortcuts.setShortcutItem

PropTypeDefaultNote
typeImgstringletterurl, icon, letter
iconobjecticon, you can only use it as the typeImg is icon.
colorTextstring#FFFFFF #FFFFFFText color, you can only use it as the typeImg is letter.
colorCirclestring#64B5F6 #64B5F6Circle color, you can only use it as the typeImg is letter.
urlImgstringImage url, you can only use it as the typeImg is url.
shortLabelstring
longLabelstring
typeIntentstringappUri, allows you to open an intent to an external app, see: examples App, allows you to open the app itself by passing the objects defined in infoIntent, see: infoIntent
appUristring
setPackagestring
infoIntentobjectinfoIntent, you can only use it as the typeIntent is app.

icon

PropTypeDefaultNote
familystringIcon family type
namestringIcon name
colorTextstring#FFFFFF #FFFFFFText color.
colorCirclestring#64B5F6 #64B5F6Circle color.

See: react-native-vector-icons To search for icons: react-native-vector-icons

Some examples of appUri and setPackage

Open page browser

appUrisetPackageNote
https://www.google.com/

Facebook

appUrisetPackageNote
https://www.facebook.com/+idcom.facebook.katana
fb://facewebmodal/f?href=https://www.facebook.com/+idcom.facebook.katana

Instagram

appUrisetPackageNote
http://instagram.com/+idcom.instagram.android
http://instagram.com/_u/+idcom.instagram.android

Twitter

appUrisetPackageNote
https://twitter.com/+idcom.twitter.android
twitter://user?screen_name=+idcom.twitter.android
https://twitter.com/intent/tweet?text=%23+text
https://twitter.com/search?f=tweets&q=+text

Google Play Store

appUrisetPackageNote
https://play.google.com/store/apps/details?id=+idcom.android.vending
market://details?id=+idcom.android.vending

Youtube

appUrisetPackageNote
http://www.youtube.com/watch?v=+id
vnd.youtube:+id

Some examples of infoIntent

infoIntent: {
paramOne: 21,//int
paramTwo: "James Bond",//string
paramThree: 0.07,//float
....
}

Some suggested colors

  • #e57373 #e57373
  • #f06292 #f06292
  • #ba68c8 #ba68c8
  • #9575cd #9575cd
  • #7986cb #7986cb
  • #64b5f6 #64b5f6
  • #4fc3f7 #4fc3f7
  • #4dd0e1 #4dd0e1
  • #4db6ac #4db6ac
  • #81c784 #81c784
  • #aed581 #aed581
  • #dce775 #dce775
  • #fff176 #fff176
  • #ffd54f #ffd54f
  • #ffb74d #ffb74d
  • #ff8a65 #ff8a65
  • #a1887f #a1887f
  • #e0e0e0 #e0e0e0
  • #90a4ae #90a4ae
  • #000000 #000000

📜 License

This library is provided under the Apache License.