Skip to content

Commit

Permalink
Merge pull request #1 from congnguyen91/master
Browse files Browse the repository at this point in the history
- Fix build ios & android
  • Loading branch information
prscX authored Mar 19, 2018
2 parents 44b5fac + a9ed02d commit 005d34d
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 56 deletions.
70 changes: 51 additions & 19 deletions Example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@
* @flow
*/

import React, { Component } from "react";
import { Platform, StyleSheet, Text, View, Button } from "react-native";

import React, { Component } from 'react';
import {
AppTour,
AppTourSequence,
AppTourView
} from "react-native-app-tour";
Platform,
StyleSheet,
Text,
View,
Button,
DeviceEventEmitter,
} from 'react-native';

import { AppTour, AppTourSequence, AppTourView } from 'react-native-app-tour';

import Top from "./components/Top";
import Center from "./components/Center";
import Bottom from "./components/Bottom";
import Top from './components/Top';
import Center from './components/Center';
import Bottom from './components/Bottom';

const instructions = Platform.select({
ios: "Press Cmd+R to reload,\n" + "Cmd+D or shake for dev menu",
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
"Double tap R on your keyboard to reload,\n" +
"Shake or press menu button for dev menu"
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});

export default class App extends Component<{}> {
Expand All @@ -31,6 +34,11 @@ export default class App extends Component<{}> {
this.appTourTargets = [];
}

componentWillMount() {
this.registerSequenceStepEvent();
this.registerFinishSequenceEvent();
}

componentDidMount() {
setTimeout(() => {
let appTourSequence = new AppTourSequence();
Expand All @@ -41,6 +49,30 @@ export default class App extends Component<{}> {
}, 1000);
}

registerSequenceStepEvent = () => {
if (this.sequenceStepListener) {
this.sequenceStepListener.remove();
}
this.sequenceStepListener = DeviceEventEmitter.addListener(
'onShowSequenceStepEvent',
(e: Event) => {
console.log(e);
}
);
};

registerFinishSequenceEvent = () => {
if (this.finishSequenceListener) {
this.finishSequenceListener.remove();
}
this.finishSequenceListener = DeviceEventEmitter.addListener(
'onFinishSequenceEvent',
(e: Event) => {
console.log(e);
}
);
};

render() {
return (
<View style={styles.container}>
Expand Down Expand Up @@ -70,16 +102,16 @@ export default class App extends Component<{}> {
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: "column",
justifyContent: "space-between"
flexDirection: 'column',
justifyContent: 'space-between',
},
top: {
flex: 1
flex: 1,
},
center: {
flex: 1
flex: 1,
},
bottom: {
flex: 1
}
flex: 1,
},
});
2 changes: 2 additions & 0 deletions Example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
buildscript {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
Expand All @@ -20,5 +21,6 @@ allprojects {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { url "https://jitpack.io" }
}
}
9 changes: 4 additions & 5 deletions Example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
target 'Example' do
use_frameworks!

#pod 'MaterialShowcase'
pod 'MaterialShowcase', '~> 0.5.1'
#pod 'MaterialShowcase',:git => 'https://github.com/aromajoin/material-showcase-ios.git', :tag => '0.5.1'
#pod 'MaterialShowcase', '~> 0.5.1'
pod 'MaterialShowcase',:git => 'https://github.com/aromajoin/material-showcase-ios.git', :commit =>'b8d8c1dbd752dc3057ca9c99aba9fea93b85e614'

post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name.include?('MaterialShowcase')
target.build_configurations.each do |config|
# swift version 4.0 for xcode 9
config.build_settings['SWIFT_VERSION'] = '4.0'
#config.build_settings['SWIFT_VERSION'] = '4.0'
# swift version 3.2 for xcode 8
#config.build_settings['SWIFT_VERSION'] = '3.2'
config.build_settings['SWIFT_VERSION'] = '3.2'
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ repositories {

dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.getkeepsafe.taptargetview:taptargetview:1.10.0'
compile 'com.getkeepsafe.taptargetview:taptargetview:1.11.0'
}

39 changes: 37 additions & 2 deletions android/src/main/java/ui/apptour/RNAppTourModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
import android.content.res.Resources;
import android.graphics.Color;
import android.util.Log;
import android.support.annotation.Nullable;

import com.facebook.common.internal.Objects;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactContext;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;

import com.facebook.react.modules.core.DeviceEventManagerModule;

import com.getkeepsafe.taptargetview.TapTargetSequence;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.getkeepsafe.taptargetview.TapTarget;
Expand All @@ -40,6 +45,14 @@ public String getName() {
return "RNAppTour";
}

private void sendEvent(ReactContext reactContext,
String eventName,
@Nullable WritableMap params) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}

@ReactMethod
public void ShowSequence(final ReadableArray views, final ReadableMap props, final Promise promise) {
final Activity activity = this.getCurrentActivity();
Expand All @@ -54,7 +67,29 @@ public void ShowSequence(final ReadableArray views, final ReadableMap props, fin
@Override
public void run() {
TapTargetSequence tapTargetSequence = new TapTargetSequence(activity).targets(targetViews);
tapTargetSequence.continueOnCancel(true);
tapTargetSequence.listener(new TapTargetSequence.Listener() {
@Override
public void onSequenceFinish() {
WritableMap params = Arguments.createMap();
params.putBoolean("finish", true);
sendEvent(reactContext, "onFinishSequenceEvent", params);
}

@Override
public void onSequenceStep(TapTarget lastTarget, boolean targetClicked) {
WritableMap params = Arguments.createMap();
params.putBoolean("next_step", true);
sendEvent(reactContext, "onShowSequenceStepEvent", params);
}

@Override
public void onSequenceCanceled(TapTarget lastTarget) {
WritableMap params = Arguments.createMap();
params.putBoolean("cancel_step", true);
sendEvent(reactContext, "onCancelStepEvent", params);
}
})
.continueOnCancel(true);
tapTargetSequence.start();
}
});
Expand Down Expand Up @@ -158,4 +193,4 @@ private TapTarget generateTapTarget(final int view, final ReadableMap props) {

return targetView;
}
}
}
3 changes: 1 addition & 2 deletions ios/RNAppTour.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

#import <React/RCTUIManager.h>
#import <MaterialShowcase/MaterialShowcase-Swift.h>
#import "MaterialShowcase/MaterialShowcase-Swift.h"

@interface MutableOrderedDictionary<__covariant KeyType, __covariant ObjectType> : NSDictionary<KeyType, ObjectType>
@end


@interface RNAppTour : NSObject<RCTBridgeModule> {
MutableOrderedDictionary *targets;
}
Expand Down
92 changes: 67 additions & 25 deletions ios/RNAppTour.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,67 @@ - (dispatch_queue_t)methodQueue {
}


- (NSTextAlignment*) getTextAlignmentByString: (NSString*) strAlignment {
if (strAlignment == nil) {
return NSTextAlignmentLeft; // default is left
}

NSString *lowCaseString = [strAlignment lowercaseString];
if ([lowCaseString isEqualToString:@"left"]) {
return NSTextAlignmentLeft;
} if ([lowCaseString isEqualToString:@"right"]) {
return NSTextAlignmentRight;
} if ([lowCaseString isEqualToString:@"center"]) {
return NSTextAlignmentCenter;
} if ([lowCaseString isEqualToString:@"justify"]) {
return NSTextAlignmentJustified;
}

return NSTextAlignmentLeft;
}

- (CGFloat) colorComponentFrom: (NSString *) string start: (NSUInteger) start length: (NSUInteger) length {
NSString *substring = [string substringWithRange: NSMakeRange(start, length)];
NSString *fullHex = length == 2 ? substring : [NSString stringWithFormat: @"%@%@", substring, substring];
unsigned hexComponent;
[[NSScanner scannerWithString: fullHex] scanHexInt: &hexComponent];
return hexComponent / 255.0;
}

- (UIColor *) colorWithHexString: (NSString *) hexString {
NSString *colorString = [[hexString stringByReplacingOccurrencesOfString: @"#" withString: @""] uppercaseString];
CGFloat alpha, red, blue, green;
switch ([colorString length]) {
case 3: // #RGB
alpha = 1.0f;
red = [self colorComponentFrom: colorString start: 0 length: 1];
green = [self colorComponentFrom: colorString start: 1 length: 1];
blue = [self colorComponentFrom: colorString start: 2 length: 1];
break;
case 4: // #ARGB
alpha = [self colorComponentFrom: colorString start: 0 length: 1];
red = [self colorComponentFrom: colorString start: 1 length: 1];
green = [self colorComponentFrom: colorString start: 2 length: 1];
blue = [self colorComponentFrom: colorString start: 3 length: 1];
break;
case 6: // #RRGGBB
alpha = 1.0f;
red = [self colorComponentFrom: colorString start: 0 length: 2];
green = [self colorComponentFrom: colorString start: 2 length: 2];
blue = [self colorComponentFrom: colorString start: 4 length: 2];
break;
case 8: // #AARRGGBB
alpha = [self colorComponentFrom: colorString start: 0 length: 2];
red = [self colorComponentFrom: colorString start: 2 length: 2];
green = [self colorComponentFrom: colorString start: 4 length: 2];
blue = [self colorComponentFrom: colorString start: 6 length: 2];
break;
default:
return nil;
}
return [UIColor colorWithRed: red green: green blue: blue alpha: alpha];
}

RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(ShowSequence:(NSArray *)views props:(NSDictionary *)props)
Expand Down Expand Up @@ -142,7 +203,7 @@ - (MaterialShowcase *)generateMaterialShowcase:(NSNumber *)view props:(NSDiction
UIColor *backgroundPromptColor;
NSString *backgroundPromptColorValue = [props objectForKey:@"backgroundPromptColor"];
if (backgroundPromptColorValue != nil) {
backgroundPromptColor = [UIColor fromHexWithHexString: backgroundPromptColorValue];
backgroundPromptColor = [self colorWithHexString: backgroundPromptColorValue];
}
if (backgroundPromptColor != nil) {
[materialShowcase setBackgroundColor: backgroundPromptColor];
Expand All @@ -160,11 +221,11 @@ - (MaterialShowcase *)generateMaterialShowcase:(NSNumber *)view props:(NSDiction
UIColor *targetHolderColor;
NSString *targetTintColorValue = [props objectForKey:@"targetTintColor"];
if (targetTintColorValue != nil) {
targetTintColor = [UIColor fromHexWithHexString: targetTintColorValue];
targetTintColor = [self colorWithHexString: targetTintColorValue];
}
NSString *targetHolderColorValue = [props objectForKey:@"targetHolderColor"];
if (targetHolderColorValue != nil) {
targetHolderColor = [UIColor fromHexWithHexString: targetHolderColorValue];
targetHolderColor = [self colorWithHexString: targetHolderColorValue];
}


Expand Down Expand Up @@ -195,12 +256,12 @@ - (MaterialShowcase *)generateMaterialShowcase:(NSNumber *)view props:(NSDiction

NSString *primaryTextColorValue = [props objectForKey:@"primaryTextColor"];
if (primaryTextColorValue != nil) {
primaryTextColor = [UIColor fromHexWithHexString: primaryTextColorValue];
primaryTextColor = [self colorWithHexString:primaryTextColorValue];
}

NSString *secondaryTextColorValue = [props objectForKey:@"secondaryTextColor"];
if (secondaryTextColorValue != nil) {
secondaryTextColor = [UIColor fromHexWithHexString: secondaryTextColorValue];
secondaryTextColor = [self colorWithHexString:secondaryTextColorValue];
}

[materialShowcase setPrimaryText: primaryText];
Expand Down Expand Up @@ -242,7 +303,7 @@ - (MaterialShowcase *)generateMaterialShowcase:(NSNumber *)view props:(NSDiction
UIColor *aniRippleColor;
NSString *aniRippleColorValue = [props objectForKey:@"aniRippleColor"];
if (aniRippleColorValue != nil) {
aniRippleColor = [UIColor fromHexWithHexString: aniRippleColorValue];
aniRippleColor = [self colorWithHexString: aniRippleColorValue];
} if (aniRippleColor != nil) {
[materialShowcase setAniRippleColor: aniRippleColor];
}
Expand All @@ -266,23 +327,4 @@ - (MaterialShowcase *)generateMaterialShowcase:(NSNumber *)view props:(NSDiction
return materialShowcase;
}

- (NSTextAlignment*) getTextAlignmentByString: (NSString*) strAlignment {
if (strAlignment == nil) {
return NSTextAlignmentLeft; // default is left
}

NSString *lowCaseString = [strAlignment lowercaseString];
if ([lowCaseString isEqualToString:@"left"]) {
return NSTextAlignmentLeft;
} if ([lowCaseString isEqualToString:@"right"]) {
return NSTextAlignmentRight;
} if ([lowCaseString isEqualToString:@"center"]) {
return NSTextAlignmentCenter;
} if ([lowCaseString isEqualToString:@"justify"]) {
return NSTextAlignmentJustified;
}
return NSTextAlignmentLeft;
}

@end

Loading

0 comments on commit 005d34d

Please sign in to comment.