Skip to content

Commit

Permalink
- migrating to latest gradle 3.1.2
Browse files Browse the repository at this point in the history
- migrating to rn 0.55.4
- enabling support for dismiss tooltip programmatically
  • Loading branch information
prscms committed May 30, 2018
1 parent 74a51ce commit d280b17
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 32 deletions.
9 changes: 7 additions & 2 deletions Example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ export default class App extends Component<Props> {

this.state = {
visible: false,
dismiss: false,
reference: undefined
}
}

_onPress (ref) {
this.setState({ visible: true, reference: ref });
this.setState({ visible: true, dismiss: false, reference: ref });

// setTimeout(() => {
// this.setState({ dismiss: true })
// }, 1000)
}

render() {
Expand All @@ -46,7 +51,7 @@ export default class App extends Component<Props> {
<Bottom style={styles.bottom} onPress={ref => {
this._onPress(ref);
}} />
<Tooltips text={"Long Press Description"} visible={this.state.visible} reference={this.state.reference} onHide={() => {
<Tooltips text={"Long Press Description"} visible={this.state.visible} dismiss={this.state.dismiss} reference={this.state.reference} autoHide={true} onHide={() => {
console.log("On Hide");
}} />
</View>;
Expand Down
4 changes: 2 additions & 2 deletions Example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -17,10 +17,10 @@ allprojects {
repositories {
mavenLocal()
jcenter()
google()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
google()
}
}
4 changes: 2 additions & 2 deletions Example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Feb 06 21:13:13 IST 2018
#Wed May 30 14:57:15 IST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
4 changes: 2 additions & 2 deletions Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "jest"
},
"dependencies": {
"react": "16.2.0",
"react-native": "0.53.0",
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-tooltips": "../"
},
"devDependencies": {
Expand Down
42 changes: 26 additions & 16 deletions RNTooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Tooltips extends Component {
autoHide: PropTypes.bool,
duration: PropTypes.number,
clickToHide: PropTypes.bool,
dismiss: PropTypes.bool,
corner: PropTypes.number,
tintColor: PropTypes.string,
textColor: PropTypes.string,
Expand All @@ -55,6 +56,7 @@ class Tooltips extends Component {
position: 4,
align: 2,
autoHide: true,
dismiss: false,
duration: Platform.OS === "android" ? 4000 : 4,
clickToHide: false,
corner: Platform.OS === "android" ? 30 : 0,
Expand Down Expand Up @@ -104,24 +106,32 @@ class Tooltips extends Component {
);
}

static Dismiss(ref) {
RNTooltips.Dismiss(ref);
}

componentDidUpdate() {
if (this.props.visible && this.props.reference) {
Tooltips.Show(findNodeHandle(this.props.reference), {
text: this.props.text,
position: this.props.position,
align: this.props.align,
autoHide: this.props.autoHide,
duration: this.props.duration,
clickToHide: this.props.clickToHide,
corner: this.props.corner,
tintColor: this.props.tintColor,
textColor: this.props.textColor,
textSize: this.props.textSize,
arrow: this.props.arrow,
gravity: this.props.gravity,
shadow: this.props.shadow,
onHide: this.props.onHide
});
if (this.props.dismiss) {
Tooltips.Dismiss(findNodeHandle(this.props.reference))
} else {
Tooltips.Show(findNodeHandle(this.props.reference), {
text: this.props.text,
position: this.props.position,
align: this.props.align,
autoHide: this.props.autoHide,
duration: this.props.duration,
clickToHide: this.props.clickToHide,
corner: this.props.corner,
tintColor: this.props.tintColor,
textColor: this.props.textColor,
textSize: this.props.textSize,
arrow: this.props.arrow,
gravity: this.props.gravity,
shadow: this.props.shadow,
onHide: this.props.onHide
});
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
buildscript {
repositories {
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:3.1.2'
}
}

Expand All @@ -28,11 +29,11 @@ android {

repositories {
mavenCentral()
google()
}

dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.tomergoldst.android:tooltips:1.0.9'
compile 'com.github.florent37:viewtooltip:1.1.4'
compile 'com.github.florent37:viewtooltip:1.1.5'
}

14 changes: 11 additions & 3 deletions android/src/main/java/com/reactlibrary/RNTooltipsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.views.view.ReactViewGroup;
import com.github.florent37.viewtooltip.ViewTooltip;
import com.tomergoldst.tooltips.ToolTip;
import com.tomergoldst.tooltips.ToolTipsManager;

public class RNTooltipsModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;
private ViewTooltip tooltip;

public RNTooltipsModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand Down Expand Up @@ -52,7 +51,7 @@ public void Show(final int view, final ReadableMap props, final Callback onHide)
int gravity = props.getInt("gravity");
boolean arrow = props.getBoolean("arrow");

ViewTooltip tooltip = ViewTooltip.on(reactContext.getCurrentActivity(), target);
tooltip = ViewTooltip.on(reactContext.getCurrentActivity(), target);
tooltip = tooltip.text(text);

if (!arrow) {
Expand Down Expand Up @@ -95,4 +94,13 @@ public void onHide(View view) {

tooltip.show();
}

@ReactMethod
public void Dismiss(final int view) {

if (tooltip == null) return;

tooltip.close();
tooltip = null;
}
}
12 changes: 11 additions & 1 deletion ios/RNTooltips.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ @interface TooltipDelegate : NSObject <SexyTooltipDelegate>

@implementation TooltipDelegate
- (void)tooltipDidDismiss:(SexyTooltip *)tooltip {
tooltip = nil;
_onHide(@[]);
}

Expand All @@ -19,6 +20,8 @@ - (void)tooltipDidDismiss:(SexyTooltip *)tooltip {

@implementation RNTooltips

SexyTooltip *toolTip;

@synthesize bridge = _bridge;

- (dispatch_queue_t)methodQueue
Expand Down Expand Up @@ -50,7 +53,7 @@ - (dispatch_queue_t)methodQueue
[attributes addAttribute:NSForegroundColorAttributeName value:[RNTooltips colorFromHexCode: textColor] range:NSMakeRange(0, text.length)];
[attributes addAttribute:NSFontAttributeName value: [UIFont systemFontOfSize: [textSize floatValue]] range:NSMakeRange(0,text.length)];

SexyTooltip *toolTip = [[SexyTooltip alloc] initWithAttributedString: attributes];
toolTip = [[SexyTooltip alloc] initWithAttributedString: attributes];

TooltipDelegate *delegate = [[TooltipDelegate alloc] init];
delegate.onHide = onHide;
Expand All @@ -74,6 +77,13 @@ - (dispatch_queue_t)methodQueue
[toolTip presentFromView:target animated:YES];
}

RCT_EXPORT_METHOD(Dismiss:(nonnull NSNumber *)view) {

if (toolTip == nil) return;

[toolTip dismiss];
toolTip = nil;
}


+ (UIColor *) colorFromHexCode:(NSString *)hexString {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-tooltips",
"version": "0.0.5",
"version": "0.0.6",
"description": "React Native: Native Tooltip View",
"main": "RNTooltips.js",
"scripts": {
Expand All @@ -13,6 +13,9 @@
"type": "git",
"url": "https://github.com/prscX/react-native-tooltips.git"
},
"devDependencies": {
"prettier-pack": "0.0.6"
},
"author": "Pranav Raj Singh Chauhan",
"license": "MIT"
}

0 comments on commit d280b17

Please sign in to comment.