Skip to content

Commit

Permalink
Merge branch 'yesemincidem-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiemo Bleeken committed Jul 16, 2017
2 parents 1423292 + 1fcb07a commit 6ab0431
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 110 deletions.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,48 @@ import Toast from 'react-native-simple-toast';

Toast.show('This is a toast.');
Toast.show('This is a long toast.',Toast.LONG);
```
```
## Options

Toast was been able to make customizable through these properties

```javascript
{
width:300,
height:50,
backgroundColor: "#C2F8FF",
color: "#ffffff",
borderWidth: 3,
borderColor: "#C2F8FF",
borderRadius: 3
}

```
if you want to make a customizable toast,you add an object like above to `show` and `showGravity`

#### Example usage:

```javascript
import Toast from 'react-native-simple-toast';
const style={
width:300,
height:50,
backgroundColor: "#C2F8FF",
color: "#ffffff",
borderWidth: 3,
borderColor: "#C2F8FF",
borderRadius: 3
};
Toast.show('This is a long toast.',Toast.LONG,style);


Toast.showWithGravity(message, Toast.SHORT,Toast.TOP,style)
```
These are properties that can make customizable
`width`,
`height`,
`backgroundColor`,
`color`,
`borderColor`,
`borderWidth`
You can make customizable all of them or some of them or you can use default toast style.
42 changes: 22 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@ import {NativeModules,ToastAndroid,Platform} from 'react-native';
var RCTToastAndroid = Platform.OS === 'android' ? ToastAndroid : NativeModules.LRDRCTSimpleToast;

var SimpleToast = {
// Toast duration constants
SHORT: RCTToastAndroid.SHORT,
LONG: RCTToastAndroid.LONG,
// Toast duration constants
SHORT: RCTToastAndroid.SHORT,
LONG: RCTToastAndroid.LONG,

// Toast gravity constants
TOP: RCTToastAndroid.TOP,
BOTTOM: RCTToastAndroid.BOTTOM,
CENTER: RCTToastAndroid.CENTER,
// Toast gravity constants
TOP: RCTToastAndroid.TOP,
BOTTOM: RCTToastAndroid.BOTTOM,
CENTER: RCTToastAndroid.CENTER,

show: function (
message,
duration
) {
RCTToastAndroid.show(message, duration === undefined ? this.SHORT : duration);
},
show: function (
message,
duration,
customStyle
) {
RCTToastAndroid.show(message, duration === undefined ? this.SHORT : duration,customStyle);
},

showWithGravity: function (
message,
duration,
gravity,
) {
RCTToastAndroid.showWithGravity(message, duration === undefined ? this.SHORT : duration, gravity);
},
showWithGravity: function (
message,
duration,
gravity,
customStyle
) {
RCTToastAndroid.showWithGravity(message, duration === undefined ? this.SHORT : duration, customStyle, gravity);
},
};

export default SimpleToast;
41 changes: 35 additions & 6 deletions ios/LRDRCTSimpleToast/LRDRCTSimpleToast.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,45 @@ - (NSDictionary *)constantsToExport {
};
}

RCT_EXPORT_METHOD(show:(NSString *)msg duration:(double)duration {
[self _show:msg duration:duration gravity:LRDRCTSimpleToastGravityBottom];
RCT_EXPORT_METHOD(show:(NSString *)msg duration:(double)duration customStyle:(NSDictionary *)customStyle {
[self _show:msg duration:duration customStyle:customStyle gravity:LRDRCTSimpleToastGravityBottom];
});

RCT_EXPORT_METHOD(showWithGravity:(NSString *)msg duration:(double)duration gravity:(nonnull NSNumber *)gravity{
[self _show:msg duration:duration gravity:gravity.intValue];
RCT_EXPORT_METHOD(showWithGravity:(NSString *)msg duration:(double)duration customStyle:(NSDictionary *)customStyle gravity:(nonnull NSNumber *)gravity{
[self _show:msg duration:duration customStyle:customStyle gravity:gravity.intValue];
});

- (void)_show:(NSString *)msg duration:(NSTimeInterval)duration gravity:(NSInteger)gravity {
- (UIViewController *)visibleViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil)
{
return rootViewController;
}
if ([rootViewController.presentedViewController isKindOfClass:[UINavigationController class]])
{
UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController;
UIViewController *lastViewController = [[navigationController viewControllers] lastObject];

return [self visibleViewController:lastViewController];
}
if ([rootViewController.presentedViewController isKindOfClass:[UITabBarController class]])
{
UITabBarController *tabBarController = (UITabBarController *)rootViewController.presentedViewController;
UIViewController *selectedViewController = tabBarController.selectedViewController;

return [self visibleViewController:selectedViewController];
}

UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController;

return [self visibleViewController:presentedViewController];
}

- (void)_show:(NSString *)msg duration:(NSTimeInterval)duration customStyle:(NSDictionary *)customStyle gravity:(NSInteger)gravity {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *root = [[[[[UIApplication sharedApplication] delegate] window] rootViewController] view];
//UIView *root = [[[[[UIApplication sharedApplication] delegate] window] rootViewController] view];
UIViewController *ctrl = [self visibleViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
UIView *root = [ctrl view];
CGRect bound = root.bounds;
bound.size.height -= _keyOffset;
if (bound.size.height > LRDRCTSimpleToastBottomOffset*2) {
Expand All @@ -97,6 +125,7 @@ - (void)_show:(NSString *)msg duration:(NSTimeInterval)duration gravity:(NSInteg
[view makeToast:msg
duration:duration
position:position
customStyle:customStyle
title:nil
image:nil
style:nil
Expand Down
36 changes: 23 additions & 13 deletions ios/LRDRCTSimpleToast/UIView+Toast.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,51 @@ extern const NSString * CSToastPositionBottom;
@param duration The toast duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param customStyle The toast customizable style
*/
- (void)makeToast:(NSString *)message
duration:(NSTimeInterval)duration
position:(id)position;
position:(id)position
customStyle:(NSDictionary *)customStyle;

/**
Creates and presents a new toast view with a message. Duration, position, and
style can be set explicitly.
@param message The message to be displayed
@param duration The toast duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param style The style. The shared style will be used when nil
@param customStyle The style.The toast customizable style when not nil
*/
- (void)makeToast:(NSString *)message
duration:(NSTimeInterval)duration
position:(id)position
customStyle:(NSDictionary *)customStyle
style:(CSToastStyle *)style;

/**
Creates and presents a new toast view with a message, title, and image. Duration,
position, and style can be set explicitly. The completion block executes when the
toast view completes. `didTap` will be `YES` if the toast view was dismissed from
toast view completes. `didTap` will be `YES` if the toast view was dismissed from
a tap.
@param message The message to be displayed
@param duration The toast duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param title The title
@param image The image
@param style The style. The shared style will be used when nil
@param customStyle The style.The toast customizable style when not nil
@param completion The completion block, executed after the toast view disappears.
didTap will be `YES` if the toast view was dismissed from a tap.
*/
- (void)makeToast:(NSString *)message
duration:(NSTimeInterval)duration
position:(id)position
customStyle:(NSDictionary *)customStyle
title:(NSString *)title
image:(UIImage *)image
style:(CSToastStyle *)style
Expand All @@ -108,30 +114,32 @@ extern const NSString * CSToastPositionBottom;
The look and feel is configured via the style. Unlike the `makeToast:` methods,
this method does not present the toast view automatically. One of the showToast:
methods must be used to present the resulting view.
@warning if message, title, and image are all nil, this method will return nil.
@param message The message to be displayed
@param title The title
@param image The image
@param style The style. The shared style will be used when nil
@param customStyle The style.The toast customizable style when not nil
@return The newly created toast view
*/
- (UIView *)toastViewForMessage:(NSString *)message
customStyle:(NSDictionary *)customStyle
title:(NSString *)title
image:(UIImage *)image
style:(CSToastStyle *)style;

/**
Creates and displays a new toast activity indicator view at a specified position.
@warning Only one toast activity indicator view can be presented per superview. Subsequent
calls to `makeToastActivity:` will be ignored until hideToastActivity is called.
@warning `makeToastActivity:` works independently of the showToast: methods. Toast activity
views can be presented and dismissed while toast views are being displayed. `makeToastActivity:`
has no effect on the queueing behavior of the showToast: methods.
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
*/
Expand All @@ -144,26 +152,28 @@ extern const NSString * CSToastPositionBottom;

/**
Displays any view as toast using the default duration and position.
@param toast The view to be displayed as toast
*/
- (void)showToast:(UIView *)toast;

/**
Displays any view as toast at a provided position and duration. The completion block
executes when the toast view completes. `didTap` will be `YES` if the toast view was
Displays any view as toast at a provided position and duration. The completion block
executes when the toast view completes. `didTap` will be `YES` if the toast view was
dismissed from a tap.
@param toast The view to be displayed as toast
@param duration The notification duration
@param position The toast's center point. Can be one of the predefined CSToastPosition
constants or a `CGPoint` wrapped in an `NSValue` object.
@param completion The completion block, executed after the toast view disappears.
didTap will be `YES` if the toast view was dismissed from a tap.
@param customStyle The toast customizable style.
*/
- (void)showToast:(UIView *)toast
duration:(NSTimeInterval)duration
position:(id)position
customStyle:(NSDictionary *)customStyle
completion:(void(^)(BOOL didTap))completion;

@end
Expand Down
Loading

0 comments on commit 6ab0431

Please sign in to comment.