1.0.4 • Published 9 months ago

link-lab v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

Native Interface Library

This library facilitates seamless communication between a web application and native modules, enabling various actions such as interacting with native device features, fetching app data, and handling notifications.

Features

  • Webview Initialization: Notify native layers when the webview is ready.
  • App Info Fetching: Retrieve app-specific information.
  • Deep Linking: Open specific app sections via deep links.
  • URL Handling: Open URLs in a browser or native layers.
  • Social Sharing: Share content across social platforms.
  • Camera & Gallery Access: Open front/back cameras or the device gallery.
  • Notification Management: Schedule notifications.
  • QR Code Scanning: Scan QR codes using the device camera.
  • Device Features: Trigger vibrations, capture screenshots, toggle loaders, and more.

Installation

To include this library in your project:

npm install dining-native-bridge-client

Usage

Import the Library

import NativeBridge from 'dining-native-bridge-client';

Initialize the Native Interface

Ensure the interface is properly initialized before invoking any native calls:

NativeBridge.init()
  .then(() => console.log('Native interface initialized!'))
  .catch((error) => console.error('Initialization failed:', error));

Check Initialization Status

if (NativeBridge.isNativeInitialized()) {
  console.log('Native interface is active.');
} else {
  console.log('Native support not available.');
}

Example API Calls

Open a Deep Link

NativeBridge.openDeeplink('myapp://home')
  .then(() => console.log('Deep link opened!'))
  .catch((error) => console.error('Failed to open deep link:', error));

Share Content via Social Media

NativeBridge.socialShare(
  'https://example.com',
  'Awesome Content',
  'Check out this amazing content!',
  'https://example.com/image.jpg'
)
  .then(() => console.log('Content shared!'))
  .catch((error) => console.error('Sharing failed:', error));

Schedule a Notification

NativeBridge.scheduleNotification(
  'Reminder',
  'Don\'t forget to check the app!',
  '2024-12-12T10:00:00Z'
)
  .then(() => console.log('Notification scheduled!'))
  .catch((error) => console.error('Notification scheduling failed:', error));

Capture a Screenshot

NativeBridge.captureScreenshot()
  .then((screenshotPath) => console.log('Screenshot saved at:', screenshotPath))
  .catch((error) => console.error('Screenshot failed:', error));

API Reference

Initialization

  • init(): Initializes the native interface. Returns a promise.
  • isNativeInitialized(): Checks if the native interface is active. Returns a boolean.

Native Callback Map

  • webviewInitComplete(): Notifies the native layer that the webview is ready.
  • getAppInfo(): Fetches app information from the native layer.
  • openDeeplink(url): Opens a deep link in the app.
  • openUrl(url): Opens a URL in the browser or native layer.
  • socialShare(url, title, description, image): Shares content on social platforms.
  • openFrontCamera(): Opens the front camera.
  • openBackCamera(): Opens the back camera.
  • closeWebView(url): Closes the webview.
  • showLoader(): Displays a loader.
  • hideLoader(): Hides the loader.
  • openGallery(): Opens the device gallery.
  • scheduleNotification(title, message, time): Schedules a notification.
  • scanQRCode(): Scans a QR code.
  • haptics(): Triggers device vibration.
  • isDarkModeEnabled(): Checks if dark mode is enabled.
  • captureScreenshot(): Captures a screenshot.
  • logoutUser(): Logs the user out of the app.
  • downloadFile(url): Downloads a file from the specified URL.

Error Handling

This library includes built-in error handling for common issues:

  • NATIVE_NOT_SUPPORT: Native capability is not supported.
  • BAD_REQUEST: Invalid input or request payload.
  • REQUEST_TIMEOUT: Native request timeout after 10 seconds.

Contribution

We welcome contributions! Please submit issues or pull requests to improve this library.


License

1.0.4

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago