Bridge SDK

To make your development process easier we created SDKs for the most popular platforms and frameworks:

Libraries

iOS

Swift SDK for iOS is available on Cocoa Pods: https://cocoapods.org/pods/truvsdk

Install

Add TruvSDK pod :

use_frameworks!

target 'MyApp' do
    pod 'TruvSDK'
end

Usage

import TruvSDK

let truvBridgeView = TruvBridgeView(token: token, delegate: self)
view.addSubview(truvBridgeView)
// add constraints if needed

Android

Kotlin SDK for Android is available on JitPack: https://jitpack.io/#truvhq/android-sdk

Install

Step 1. Add the JitPack repository to your project build.gradle file

allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

Step 2. Add the dependency to your build.gradle file:

implementation 'com.github.truvhq:android-sdk:0.2'

Usage

The TruvBridgeView is a View that you can integrate into your app's flow:

<?xml version="1.0" encoding="utf-8"?>
<com.truv.TruvBridgeView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/bridgeView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
val truvEventsListener = object : TruvEventsListener {

        override fun onClose() {
            Log.d(TAG, "Bridge Closed")
        }

        override fun onError() {
            Log.e(TAG, "Bridge Error")
        }

        override fun onEvent(event: TruvEventPayload.EventType) {
            Log.d(TAG, "Event: $event")
        }

        override fun onLoad() {
            Log.d(TAG, "Bridge Loaded")
        }

        override fun onSuccess(payload: TruvSuccessPayload) {
            Log.d(TAG, "Bridge Success")
            val token = payload.publicToken
            // Do something with your token
        }

    }

binding.bridgeView.addEventListener(truvEventsListener)

React Native

React Native SDK for iOS and Android is available on npm: https://www.npmjs.com/package/@truv/react-native

Install

With npm:

npm install @truv/react-native --save

With yarn:

yarn add -S @truv/react-native

Usage

import React, { useState } from 'react';
import TruvBridge from '@truv/react-native';

const BridgeElement = () => {
  return (
    <TruvBridge
        bridgeToken={bridgeToken}
        onClose={() => {
            console.log('bridge closed');
        }}
        onError={() => {
            console.log('bridge error');
        }}
        onEvent={(event) => console.log('event from bridge: ', event)}
        onLoad={() => {
            console.log('bridge loaded');
        }}
        onSuccess={() => {
            console.log('bridge succeeded');
        }}
    />
  );
}

Flutter

Flutter SDK for iOS and Android is available on pub.dev: https://pub.dev/packages/truv_flutter

Install

Add truv_flutter as a dependency in your pubspec.yaml file:

dependencies:
  ...
  truv_flutter: <version>

Usage

class MainScreen extends StatelessWidget {
  final bridgeToken = 'yourbridgetoken';

  Widget build(BuildContext context) {
    return TruvBridge(
      bridgeToken: bridgeToken,
      onEvent: (String event) {

      },
    );
  }
}

Vanilla JS

JS SDK for browsers is available on npm: https://www.npmjs.com/package/@truv/bridge

Install

With npm:

npm install @truv/bridge --save

With yarn:

yarn add -S @truv/bridge

Usage

import TruvBridge from '@truv/bridge'

const bridge = TruvBridge.init({
  bridgeToken: '<previously generated bridge token>', // more info https://docs.truv.com/reference/bridge-tokens_create
  onSuccess: (publicToken, metaData) => {
    console.log(publicToken, metaData);
  },
});

// when widget need to be opened
bridge.open();

React

React SDK for web is available on npm: https://www.npmjs.com/package/@truv/react

Install

With npm:

npm install @truv/react --save

With yarn:

yarn add -S @truv/react

Usage

import ReactDOM from 'react-dom';
import React, { useState } from 'react';
import TruvBridge from '@truv/react';

const BridgeElement = () => {
  const [isOpened, setOpened] = useState(false);

  return (
    <>
      <button onClick={() => setOpened(true)}>Open</button>
      <TruvBridge
        bridgeToken="<previously generated bridge token>" // more info https://docs.truv.com/reference/bridge-tokens_create
        onClose={() => setOpened(false)}
        onSuccess={(publicToken, metaData) => {
          setOpened(false);
          console.log(publicToken, metaData);
        }}
        isOpened={isOpened}
      />
    </>
  );
}