├── .gitignore ├── LICENSE ├── README.md ├── demo ├── app │ ├── App_Resources │ │ ├── Android │ │ │ ├── AndroidManifest.xml │ │ │ ├── app.gradle │ │ │ ├── drawable-hdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-ldpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-mdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-nodpi │ │ │ │ └── splash_screen.xml │ │ │ ├── drawable-xhdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-xxhdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── drawable-xxxhdpi │ │ │ │ ├── background.png │ │ │ │ ├── icon.png │ │ │ │ └── logo.png │ │ │ ├── values-v21 │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ └── values │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ └── iOS │ │ │ ├── Assets.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── icon-29.png │ │ │ │ ├── icon-29@2x.png │ │ │ │ ├── icon-29@3x.png │ │ │ │ ├── icon-40.png │ │ │ │ ├── icon-40@2x.png │ │ │ │ ├── icon-40@3x.png │ │ │ │ ├── icon-50.png │ │ │ │ ├── icon-50@2x.png │ │ │ │ ├── icon-57.png │ │ │ │ ├── icon-57@2x.png │ │ │ │ ├── icon-60@2x.png │ │ │ │ ├── icon-60@3x.png │ │ │ │ ├── icon-72.png │ │ │ │ ├── icon-72@2x.png │ │ │ │ ├── icon-76.png │ │ │ │ ├── icon-76@2x.png │ │ │ │ └── icon-83.5@2x.png │ │ │ ├── Contents.json │ │ │ ├── LaunchImage.launchimage │ │ │ │ ├── Contents.json │ │ │ │ ├── Default-568h@2x.png │ │ │ │ ├── Default-667h@2x.png │ │ │ │ ├── Default-736h@3x.png │ │ │ │ ├── Default-Landscape.png │ │ │ │ ├── Default-Landscape@2x.png │ │ │ │ ├── Default-Landscape@3x.png │ │ │ │ ├── Default-Portrait.png │ │ │ │ ├── Default-Portrait@2x.png │ │ │ │ ├── Default.png │ │ │ │ └── Default@2x.png │ │ │ ├── LaunchScreen.AspectFill.imageset │ │ │ │ ├── Contents.json │ │ │ │ ├── LaunchScreen-AspectFill.png │ │ │ │ └── LaunchScreen-AspectFill@2x.png │ │ │ └── LaunchScreen.Center.imageset │ │ │ │ ├── Contents.json │ │ │ │ ├── LaunchScreen-Center.png │ │ │ │ └── LaunchScreen-Center@2x.png │ │ │ ├── Info.plist │ │ │ ├── LaunchScreen.storyboard │ │ │ └── build.xcconfig │ ├── README.md │ ├── app.css │ ├── app.js.map │ ├── app.ts │ ├── main-page.js.map │ ├── main-page.ts │ ├── main-page.xml │ └── package.json ├── hooks │ ├── after-watch │ │ └── nativescript-dev-typescript.js │ ├── before-prepare │ │ └── nativescript-dev-typescript.js │ ├── before-watch │ │ └── nativescript-dev-typescript.js │ └── before-watchPatterns │ │ └── nativescript-dev-typescript.js ├── package-lock.json ├── package.json ├── references.d.ts └── tsconfig.json └── src ├── .npmignore ├── flashlight-common.js ├── flashlight.android.js ├── flashlight.ios.js ├── index.d.ts ├── package-lock.json ├── package.json ├── platforms └── android │ └── AndroidManifest.xml └── references.d.ts /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | node_modules/ 4 | demo/lib/ 5 | demo/platforms/ 6 | demo/app/*.js 7 | src/platforms/android/*.aar 8 | *.log -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2015 TJ VanToll 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NativeScript Flashlight Plugin 2 | A plugin for using your device's flashlight in NativeScript Android and iOS apps. 3 | 4 | [![NPM version][npm-image]][npm-url] 5 | [![Downloads][downloads-image]][npm-url] 6 | 7 | [npm-image]:http://img.shields.io/npm/v/nativescript-flashlight.svg 8 | [npm-url]:https://npmjs.org/package/nativescript-flashlight 9 | [downloads-image]:http://img.shields.io/npm/dm/nativescript-flashlight.svg 10 | 11 | ## Installation 12 | 13 | Run the following command from the root of your project: 14 | 15 | ``` 16 | $ tns plugin add nativescript-flashlight 17 | ``` 18 | 19 | This command automatically installs the necessary files, as well as stores nativescript-flashlight as a dependency in your project's `package.json` file. 20 | 21 | ## Usage 22 | 23 | To use the flashlight module you must first `require()` it: 24 | 25 | ```js 26 | // JavaScript 27 | var flashlight = require("nativescript-flashlight"); 28 | ``` 29 | 30 | Or if you’re using TypeScript, `import` the module: 31 | 32 | ```typescript 33 | // TypeScript 34 | import * as flashlight from "nativescript-flashlight"; 35 | ``` 36 | 37 | After you have a reference to the module you can then call its `on()`, `off()`, and `toggle()` methods. For example, the code below turns your device's flashlight on with an `intensity` setting of 25%. 38 | 39 | The optional `intensity` is supported __only on iOS__ and is by default `1.0`, which is 100% brightness. 40 | 41 | ```js 42 | // my-page.js 43 | var flashlight = require("nativescript-flashlight"); 44 | flashlight.on({ 45 | intensity: 0.25 46 | }); 47 | ``` 48 | 49 | In most cases you'll want to wrap your `on()` call with a check of `isAvailable()`, to handle devices where a flashlight is not available: 50 | 51 | ```js 52 | // my-page.js 53 | var flashlight = require("nativescript-flashlight"); 54 | if (flashlight.isAvailable()) { 55 | flashlight.on(); 56 | } else { 57 | alert("A flashlight is not available on your device."); 58 | } 59 | ``` 60 | 61 | ## Examples 62 | 63 | The code below creates a button that toggles the device's flashlight: 64 | 65 | ```xml 66 | 67 | 68 | 69 |