Skip to content

Instantly share code, notes, and snippets.

@danieljvdm
Created October 19, 2017 23:06
Show Gist options
  • Select an option

  • Save danieljvdm/e7f41e35540c03fbcdb16565f9518b8a to your computer and use it in GitHub Desktop.

Select an option

Save danieljvdm/e7f41e35540c03fbcdb16565f9518b8a to your computer and use it in GitHub Desktop.
Heap iOS React Native Wrapper
// @flow
import Config from 'react-native-config';
import { NativeModules } from 'react-native';
import type { UserModel } from '../models';
type Properties = { [string]: mixed };
type HeapType = {
setAppId(appId: string): void,
identify(identity: string): void,
addUserProperties(properties: Properties): void,
addEventProperties(properties: Properties): void,
removeEventProperty(property: string): void,
clearEventProperties(): void,
track(event: string, properties?: Properties): void,
enableVisualizer(): void,
changeInterval(interval: number): void,
};
const Heap: HeapType = NativeModules.RNHeap;
export const registerHeap = (user: UserModel) => {
Heap.identify(user.uuid);
Heap.addUserProperties({ email: user.email });
};
export default Heap;
//
// RNHeap.h
// Flip
//
// Created by Daniel van der Merwe on 10/17/17.
// Copyright © 2017 Flip Inc. All rights reserved.
//
#import <React/RCTBridgeModule.h>
@interface RNHeap : NSObject <RCTBridgeModule>
@end
//
// RNHeap.m
// Flip
//
// Created by Daniel van der Merwe on 10/17/17.
// Copyright © 2017 Flip Inc. All rights reserved.
//
#import "RNHeap.h"
#import "Heap.h"
@implementation RNHeap
RCT_EXPORT_MODULE();
- (dispatch_queue_t)methodQueue {
return dispatch_get_main_queue();
}
RCT_EXPORT_METHOD(setAppId:(NSString *)appId) {
[Heap setAppId:appId];
}
RCT_EXPORT_METHOD(enableVisualizer) {
[Heap enableVisualizer];
}
RCT_EXPORT_METHOD(track:(NSString *)event withProperties:(NSDictionary *)properties) {
[Heap track:event withProperties:properties];
}
RCT_EXPORT_METHOD(identify:(NSString *)identity) {
[Heap identify:identity];
}
RCT_EXPORT_METHOD(addUserProperties:(NSDictionary *)properties) {
[Heap addUserProperties:properties];
}
RCT_EXPORT_METHOD(addEventProperties:(NSDictionary *)properties) {
[Heap addEventProperties:properties];
}
RCT_EXPORT_METHOD(removeEventProperty:(NSString *)property) {
[Heap removeEventProperty:property];
}
RCT_EXPORT_METHOD(clearEventProperties) {
[Heap clearEventProperties];
}
RCT_EXPORT_METHOD(changeInterval:(double)interval) {
[Heap changeInterval:interval];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment