# React Native API

# 1. Initialize Mini-Program

Note: For initialization methods with other configuration options, please refer to the documentation SDK Initialization

const eventEmitter = new NativeEventEmitter(NativeModules.FINMopSDK);
/**
 * @param {String} appkey
 * @param {String} secret
 * @param {String} apiServer
 * @param {String} apiPrefix
 * @param {Object} eventEmitter
 * @param {Object} finMopSDK (Native module reference)
 **/
MopSDK.initialize({
	appkey:
		'Ev7QHvml1UcW98Y1GaLfRz34ReffbDESaTXbCoFyKhEm0a3gam0elOOOdZ6Twpa3HkBzlvOwJ2cyhOrMVWuuGw==',
	secret: '16f2d2700453ae51',
	apiServer: 'https://api.finclip.com',
	apiPrefix: '/api/v1/mop/',
	nativeEventEmitter: eventEmitter,
	finMopSDK: NativeModules.FINMopSDK,
})
.then(res => {
	isInited = true;
	Alert.alert('Initialization successful');
})
.catch(error => {
	Alert.alert('Initialization failed');
});

# 2. Get Currently Running Mini-Program Information

MopSDK.currentApplet().then(res => {
	console.log('currentApplet', res);
});

# 3. Close Mini-Program

/**
 * @param {String} appId
 * @param {Boolean} animated Whether to animate the close action
 **/
MopSDK.closeApplet('xxxxx', true);

# 4. Close All Currently Opened Mini-Programs

MopSDK.closeAllApplets();

# 5. Open Mini-Program via QR Code

/**
comfort * @param {String} qrcode
 **/
MopSDK.qrcodeOpenApplet(qrcode)

# 6. Clear Cached Mini-Programs

MopSDK.clearApplets();

# 7. Register Mini-Program Event Handlers

const handler = {
	forwardApplet(params) {
	// Forward Mini-Program
	var appletInfo = params.appletInfo;	
	var appId = appletInfo.appId;
	},
	getUserInfo(params) {
		// Get user information
		return {
			name: 'jimmy',
			nickName: 'jimmy chung',
			avatarUrl: 'http://xxx.jpg',
		};
	},
	getCustomMenus(appId) {
		// Click menu
		let list = [
			{
				menuId: 'menuid1',
				image: 'image',
				title: 'title',
				type: 'type',
				foo: 'foo',
			},
			{
				menuId: 'menuid2',
				image: 'image',
				title: 'title',
				type: 'type',
				foo: 'foo',
			},
		];
		return list;
	},
	onCustomMenuClick(appId,path,menuId,appInfo) {
		// Click custom menu
		console.log('onCustomMenuClick');
	},
	appletDidOpen(appId) {
		// After Mini-Program opens (iOS only)
		console.log('appletDidOpen', params);
		return params;
	},
};
/**
 * @param {Object} handler Contains the above event handler functions
 **/
MopSDK.registerAppletHandler(handler);

# 8. Register Mini-Program Extension API

const rnCustomAPI = params => {
	console.warn('Custom API rn rnCustomAPI call', params);
	return {
		errMsg: 'rnCustomAPI:ok',
		data: '100',
	};
};
/**
 * @params {String} Custom API name
 * @params {Function} Custom API implementation
 **/
MopSDK.registerExtensionApi('rnCustomAPI', rnCustomAPI);

Note

  1. The return value of a custom API should be a map type (contains key-value pairs).
  2. To trigger the failure callback, include '{command}:fail' in errMsg; to trigger the success callback, include '{command}:ok' in errMsg. Command is the API name of the custom API.
  3. The return value should be serializable content.

# 9. Register Extension API for WebView Component Used in Mini-Program

const rnWebCustomAPI = params => {
	console.warn('Webview custom API rnWebCustomAPI call', params);
	return {
		errMsg: 'rnWebCustomAPI:ok',
		data: '100',
	};
};
/**
 * @params {String} WEBVIEW Custom API name
 * @params {Function} WEBVIEW Custom API implementation
 **/
MopSDK.addWebExtentionApi('rnWebCustomAPI', rnWebCustomAPI);

// JS call within webview (requires importing finclip js sdk)
JSSDK.callNativeAPI('rnWebCustomAPI', {
	bar: 1
})

Note

  1. The return value of a custom API should be a map type (contains key-value pairs).
  2. To trigger the failure callback, include '{command}:fail' in errMsg; to return success, include '{command}:ok' in errMsg. Command is the API name of the custom API.
  3. The return value should be serializable content.

# 10. Native Calls JS Method in WebView

/**
 * @param {String} appId
 * @param {String} eventName Provided function name
 * @param {Object} eventData
 **/
MopSDK.callJS(appId, 'app2jsFunction', {
	data: 100,
})
.then(res => {
	console.warn('calljs call successful');
})
.catch(res => {
	console.warn('calljs call failed');
});

// webview
ft.onNativeAPIHandler('app2jsFunction', funtion(res){
	console.log('Call result is', res)
})

# 11. Native Sends Event to Mini-Program

/**
 * @param {String} appId
 * @param {Object} data
 **/
MopSDK.sendCustomEvent(appId, {
	evenatName: 'hello-world',
	foo: 'test',
});

# 12. Finish Mini-Program

/**
 * @param {String} appId
 * @param {Boolean} animated Whether to animate
 **/
MopSDK.finishRunningApplet(appId, true);

# 13. Set Mini-Program Transition Animation (Android Only)

/**
 * @param {String} anim 
 * SlideFromLeftToRightAnim
 * SlideFromRightToLeftAnim,
 * SlideFromTopToBottomAnim,
 * SlideFromBottomToTopAnim,
 * FadeInAnim,
 * NoneAnim
 **/
MopSDK.setActivityTransitionAnim(anim) {
© FinClip with ❤ , Since 2017