Giter Club home page Giter Club logo

nativescript-clipboard's Introduction

NativeScript Clipboard

Build Status NPM version Downloads TotalDownloads Twitter Follow

A NativeScript plugin to copy and paste data from and to the device clipboard.

๐Ÿ’ก Plugin version 2.0.0+ is compatible with NativeScript 7+. If you need to target older NativeScript versions, please stick to plugin version 1.2.0.

Installation

Run the following command from the root of your project:

tns plugin add nativescript-clipboard

Usage

TIP: Check out the demo app for TypeScript examples.

To use this plugin you must first require() it:

var clipboard = require("nativescript-clipboard");

setText

  clipboard.setText("Something relevant to put on the clipboard.").then(function() {
      console.log("OK, copied to the clipboard");
  })

setTextSync

This is the synchronous version of setText, available since plugin version 1.2.0.

  clipboard.setTextSync("Something relevant to put on the clipboard.");

getText

  clipboard.getText().then(function(content) {
      console.log("Read from clipboard: " + content);
  })

getTextSync

This is the synchronous version of getText, available since plugin version 1.2.0.

  var content = clipboard.getText();
  console.log("Read from clipboard: " + content);

Future work

Implement support for storing data (image, etc) on the clipboard. Open an issue or PR in case you like to have that.

nativescript-clipboard's People

Contributors

dukewan avatar eddyverbruggen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nativescript-clipboard's Issues

Add a sync API

Currently setting and getting text is async, but users may have a purpose for a sync version as well.

Clear the clipboard

Hi there,
it would be nice to offer a feature to clear the clipboard, like many password managers are doing it after a specified time interval.
Kind regards, David

how to get copied content longPress popup menu to clipboard.setText(data)?

Hi, there,
Thanks for the great plugin.
Is there anyone know how to send the content to clipboard.setText() when we long press,then select certain part of text contents on the web and select "copy" from a popup menu?
What I need is when a user select and copy text contents from web, clipboard will automatically get the text and set the text for further procesessing.

Any suggestion?

undefined application.android.context

Hi, I'm getting the following error while trying to use the plugin within an nativescript-angular app.
Becasuse I'm new to nativescript I'm most likely doing something wrong, and you can guide me. Or is there something here to fix?

This is the complete error:

Error in clipboard.setText: TypeError: Cannot read property 'getSystemService' of undefined (/home/linuxtest/sample-ng-todomvc/node_modules/nativescript-clipboard/clipboard.android.js:13:15)

I'm currently have version 1.1.3 of the plugin.

And here is the section where I'm trying to use your plugin


import {Component} from "angular2/core";
var clipboardModule = require("nativescript-clipboard");


@Component({
    selector: "my-clipboard",
    templateUrl: "templates/my-clipboard.html"
})
export class MyClipboard {
    greeting:string;
    constructor(){
        this.greeting = "Hello Github!";
    }

    save(text) {
        clipboardModule.setText(text).then(()=>{
            console.log(texto + ", copied to clipboard");
        });
    }

    read() {
        clipboardModule.getText().then((content)=>{
            console.log("Read from clipboard: " + content);
        });
    }
}

Thanks in advance!

Typings missing from package.json

Can you add "typings": "clipboard.d.ts" to package.json and do a version bump?

(Side note, the current NPM version doesn't include your Webpack compatibility update.)

setText not working on android

Hello there.I am using Nativescript with Vue.I have a button that fires a method on tap.

copyToClip(){
var clipboard = require("nativescript-clipboard");
clipboard.setText(this.shorted).then(function(){
console.log("OK, copied to the clipboard");
});
},

When I tap the button I get the following error log in my console :
'Error in clipboard.setText: TypeError: Cannot read property 'getSystemService' of undefined'.
Note that this doesn't work either if I replace this.shorted with something else like 'string' and it still doesn't work if a put the require before the export default section of my vue component.
I haven't tested this on IPhone yet.
Any suggestions ? Thanks a lot.

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.