Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update document #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
90 changes: 52 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#GJRedDot
这是一个小红点的解决方案,你可以方便的使用它去管理你的小红点提示。如有bug或者建议,请提issue或PR,感谢支持。
# GJRedDot

##使用场景
我们的项目中,有很多小红点联动的需求,例如上一级页面的小红点受下一级页面小红点的影响,比如微信的“发现——朋友圈”,当朋友圈有新消息时,发现tab页面朋友圈cell中的icon上会有一个小红点,这时发现tab的icon上也有一个小红点,但是当我们点击“发现tab“的时候,小红点并不消失,而是点击朋友圈cell后,cell上和“发现tab”上的小红点同时消失,类似的需求很多APP中都可以发现。
这是一个小红点的解决方案,你可以方便的使用它去管理你的小红点提示。如有bug或者建议,请提 issue 或 PR,感谢支持。

最开始我们使用消息中心来实现,后来发现,当小红点级别变多后,代码量几何增长且分散各处,十分混乱,为了解决这个问题,我们将它进行封装。首先用key将小红点的进行关联并注册,然后只需在显示小红点的页面设置刷新block,并在任何需要刷新他的地方调用改变显示状态的方法,只需这三步即可完成。
## 使用场景

我们的项目中,有很多小红点联动的需求,例如上一级页面的小红点受下一级页面小红点的影响,比如微信的“发现——朋友圈”,当朋友圈有新消息时,发现 tab 页面朋友圈 cell 中的 icon 上会有一个小红点,这时发现 tab 的 icon 上也有一个小红点,但是当我们点击“发现 tab“的时候,小红点并不消失,而是点击朋友圈 cell 后,cell 上和“发现 tab”上的小红点同时消失,类似的需求很多 APP 中都可以发现。

最开始我们使用消息中心来实现,后来发现,当小红点级别变多后,代码量几何增长且分散各处,十分混乱,为了解决这个问题,我们将它进行封装。首先用 key 将小红点的进行关联并注册,然后只需在显示小红点的页面设置刷新 block,并在任何需要刷新他的地方调用改变显示状态的方法,只需这三步即可完成。

## 开始

支持 Pod,或手动导入文件夹 GJRedDot:

##开始
支持Pod,或手动导入文件夹GJRedDot
```bash
pod 'GJRedDot'
pod 'GJRedDot'
```

```objective-c
#import "GJRedDot.h"
#import "GJRedDot.h"
```

##注册
首先,需要在app launch中,以小红点对应的key,通过NSArray及NSDictionary关联起来,并进行注册(见Demo)
## 注册

首先,需要在 app launch 中,以小红点对应的 key,通过 NSArray 及 NSDictionary 关联起来,并进行注册(见 Demo):

```objective-c
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Expand All @@ -27,9 +32,10 @@
}
```

这个例子在Demo中:GJTabBar2是第二个tabbar的小红点Key,它与这个tab的rootVC中的icon(GJGroupKey)进行关联,GJGroupKey又与下一级页面的3个按钮(GJSunnyxxKey,GJUncleBirdKey,GJSardKey)进行关联。最后所实现的功能就是,GJSunnyxxKey,GJUncleBirdKey,GJSardKey三个按钮中有一个按钮有小红点,则GJGroupKey,GJTabBar2上也会显示小红点,如果三个按钮中小红点都消失,则GJGroupKey,GJTabBar2上的小红点才会消失
这个例子在 Demo 中:GJTabBar2 是第二个 tabbar 的小红点 Key,它与这个 tab 的 rootVC 中的 icon(GJGroupKey进行关联,GJGroupKey 又与下一级页面的3个按钮(GJSunnyxxKey,GJUncleBirdKey,GJSardKey)进行关联。最后所实现的功能就是,GJSunnyxxKey,GJUncleBirdKey,GJSardKey 三个按钮中有一个按钮有小红点,则 GJGroupKey,GJTabBar2 上也会显示小红点,如果三个按钮中小红点都消失,则 GJGroupKey,GJTabBar2 上的小红点才会消失

看着不太明白是吧?下面用伪代码解释一下:

```objective-c
- (BOOL)isShowGJTabBar2 {
if (GJGroupKey.isShow) return YES;
Expand All @@ -41,12 +47,13 @@
return YES;
}
```
是不是清晰点了?

是不是清晰点了?

注意:默认注册方法下,是使用GJRedDotModelUserDefault,将使用Key缓存到NSUserDefault中,所以请保证小红点的Key与程序中其他地方的Key区分开,以防出现问题。
注意:默认注册方法下,是使用 GJRedDotModelUserDefault,将使用Key缓存到 NSUserDefault 中,所以请保证小红点的 Key 与程序中其他地方的 Key 区分开,以防出现问题。

Demo注册代码:

```objective-c
NSString *const GJTabBar2 = @"GJTabBar2";
NSString *const GJGroupKey = @"GJAllGays";
Expand All @@ -66,47 +73,51 @@ NSString *const GJSardKey = @"GJSarkIsGay";
}
];
}

```

你也可以在需要的时候单独动态注册Key,在demo中也有示例
你也可以在需要的时候单独动态注册 Key,在 demo 中也有示例:

```objective-c
[GJRedDot registNodeWithKey:GJSarkKey parentKey:GJGroupKey];
```

[GJRedDot registNodeWithKey:GJSarkKey parentKey:GJGroupKey];
## 使用

```
在需要使用小红点的地方调用如下方法:

##使用
在需要使用小红点的地方调用如下方法
```objective-c
//将小红点刷新的callback block绑定到持有小红点的对象上(handler),当它release的时候,也自动release小红点的刷新block
//block是小红点刷新的动作,当有其他与当前key相关联的小红点状态发生变化或自身发生变化时,并影响到当前小红点状态,则进行刷新动作
//这里要使用weakSelf避免循环引用
__weak typeof(self) weakSelf = self;
[self setRedDotKey:GJGroupKey refreshBlock:^(BOOL show) {
weakSelf.gjGroupButton.showRedDot = show;
} handler:self];
//将小红点刷新的callback block绑定到持有小红点的对象上(handler),当它release的时候,也自动release小红点的刷新block
//block是小红点刷新的动作,当有其他与当前key相关联的小红点状态发生变化或自身发生变化时,并影响到当前小红点状态,则进行刷新动作
//这里要使用weakSelf避免循环引用
__weak typeof(self) weakSelf = self;
[self setRedDotKey:GJGroupKey refreshBlock:^(BOOL show) {
weakSelf.gjGroupButton.showRedDot = show;
} handler:self];
```

在需要改变小红点状态的地方调用此方法:

```objective-c
//改变小红点状态,他会自动在上一个方法中刷新小红点,以及刷新想关联的小红点状态
[self resetRedDotState:NO forKey:GJGroupKey];
//改变小红点状态,他会自动在上一个方法中刷新小红点,以及刷新想关联的小红点状态
[self resetRedDotState:NO forKey:GJGroupKey];
```

你可以通过2个方法把小红点全部置为隐藏或显示状态:
你可以通过 2 个方法把小红点全部置为隐藏或显示状态:

```objective-c
[GJRedDot resetAllNodesBecomeShown];
[GJRedDot resetAllNodesBecomeHidden];
[GJRedDot resetAllNodesBecomeShown];
[GJRedDot resetAllNodesBecomeHidden];
```

你可以在程序开始时统一设置默认的小红点大小和颜色:

```objective-c
[GJRedDot setDefaultRadius:4];
[GJRedDot setDefaultColor:[UIColor orangeColor]];
[GJRedDot setDefaultRadius:4];
[GJRedDot setDefaultColor:[UIColor orangeColor]];
```

##通过系统原生UITabBarItem添加小红点功能
## 通过系统原生 UITabBarItem 添加小红点功能

```objective-c
//VC中的方法
- (void)methodVC {
Expand Down Expand Up @@ -139,10 +150,13 @@ NSString *const GJSardKey = @"GJSarkIsGay";
self.taBarItem.customView = ....;
}
```

<img src="https://github.com/GJGroup/GJRedDot/blob/master/screenshots/demo.gif" width="375">

##给以UIView为基类的View添加小红点及badge
当设置badgeValue后,优先显示badgeValue,当badgeValue为nil后,才会根据showRedDot来显示小红点
## 给以 UIView 为基类的 View 添加小红点及 badge

当设置 badgeValue 后,优先显示 badgeValue,当 badgeValue 为 nil 后,才会根据 showRedDot 来显示小红点:

```objective-c
- (void)setRedDotWithView:(UIView *)view{
view.showRedDot = YES;
Expand All @@ -162,5 +176,5 @@ NSString *const GJSardKey = @"GJSarkIsGay";
view.badgeOffset = CGPointMake(10, 5);
}
```
<img src=https://github.com/GJGroup/GJRedDot/blob/master/screenshots/reddot.png width="375">

<img src=https://github.com/GJGroup/GJRedDot/blob/master/screenshots/reddot.png width="375">