Skip to content

Commit 27d41ee

Browse files
committed
122live
1 parent 9f515e7 commit 27d41ee

File tree

5 files changed

+51
-37
lines changed

5 files changed

+51
-37
lines changed

docs/ads/ads.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
export default {
22
index: {
33
banner: {
4-
img: require('./img/115live.png'),
5-
text: '1月15日晴明老师直播React Native教程',
6-
link: 'http://reactnative.cn/post/3311',
7-
gainfo: '115live/index'
4+
img: require('./img/122live.jpg'),
5+
text: '1月22日天地之灵直播MobX案例精讲',
6+
link: 'http://reactnative.cn/post/3337',
7+
gainfo: '122live/index'
88
}
99
},
1010
docs: {
1111
banner: {
12-
img: require('./img/115live.png'),
13-
text: '1月15日晴明老师直播React Native教程',
14-
link: 'http://reactnative.cn/post/3311',
15-
gainfo: '115live/docs'
12+
img: require('./img/122live.jpg'),
13+
text: '1月22日天地之灵直播MobX案例精讲',
14+
link: 'http://reactnative.cn/post/3337',
15+
gainfo: '122live/docs'
1616
}
1717
}
1818

docs/ads/img/122live.jpg

68.3 KB
Loading

docs/docs/0.40/text.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var styles = StyleSheet.create({
3838
</div>
3939
</div>
4040
<div class="prop">
41-
<h4 class="propTitle"><a class="anchor" name="allowfontscaling"></a><span class="platform">ios</span>allowFontScaling <span class="propType">bool</span> <a class="hash-link" href="#allowfontscaling">#</a></h4>
41+
<h4 class="propTitle"><a class="anchor" name="allowfontscaling"></a>allowFontScaling <span class="propType">bool</span> <a class="hash-link" href="#allowfontscaling">#</a></h4>
4242
<div>
4343
<p>控制字体是否要根据iOS的“文本大小”辅助选项来进行缩放。</p>
4444
</div>

docs/docs/next/native-modules-ios.md

+41-27
Original file line numberDiff line numberDiff line change
@@ -324,49 +324,32 @@ RCT_EXPORT_METHOD(updateStatusBarAnimation:(UIStatusBarAnimation)animation
324324
325325
## 给Javascript发送事件
326326
327-
即使没有被JavaScript调用,本地模块也可以给JavaScript发送事件通知。目前推荐的方式是继承`RCTEventEmitter`类,实现`suppportEvents`方法然后调用`self sendEventWithName`,如下:
327+
即使没有被JavaScript调用,本地模块也可以给JavaScript发送事件通知。最直接的方式是使用`eventDispatcher`:
328328
329329
```objective-c
330-
// CalendarManager.h
331-
#import <React/RCTBridgeModule.h>
332-
#import <React/RCTEventEmitter.h>
333-
334-
@interface CalendarManager : RCTEventEmitter <RCTBridgeModule>
335-
336-
@end
337-
```
338-
339-
```objective-c
340-
// CalendarManager.m
341-
#import "CalendarManager.h"
330+
#import <React/RCTBridge.h>
331+
#import <React/RCTEventDispatcher.h>
342332
343333
@implementation CalendarManager
344334
345-
RCT_EXPORT_MODULE();
346-
347-
- (NSArray<NSString *> *)supportedEvents
348-
{
349-
return @[@"EventReminder"];
350-
}
335+
@synthesize bridge = _bridge;
351336
352337
- (void)calendarEventReminderReceived:(NSNotification *)notification
353338
{
354339
NSString *eventName = notification.userInfo[@"name"];
355-
[self sendEventWithName:@"EventReminder" body:@{@"name": eventName}];
340+
[self.bridge.eventDispatcher sendAppEventWithName:@"EventReminder"
341+
body:@{@"name": eventName}];
356342
}
357343
358344
@end
359345
```
360346

361-
JS端可以在模块中创建一个新的NativeEventEmitter实例来订阅事件:
362-
363-
```
364-
import { NativeEventEmitter, NativeModules } from 'react-native';
365-
const { CalendarManager } = NativeModules;
347+
在JavaScript中可以这样订阅事件:
366348

367-
const calendarManagerEmitter = new NativeEventEmitter(CalendarManager);
349+
```javascript
350+
import { NativeAppEventEmitter } from 'react-native';
368351

369-
const subscription = calendarManagerEmitter.addListener(
352+
var subscription = NativeAppEventEmitter.addListener(
370353
'EventReminder',
371354
(reminder) => console.log(reminder.name)
372355
);
@@ -377,6 +360,37 @@ subscription.remove();
377360

378361
更多的给JavaScript发送事件的例子,参见[`RCTLocationObserver`](https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m).
379362

363+
## 优化无监听处理的事件
364+
365+
如果你发送了一个事件却没有任何监听处理,则会因此收到一个资源警告。要优化因此带来的额外开销,你可以在你的`RCTEventEmitter`子类中覆盖`startObserving``stopObserving`方法。
366+
367+
```objective-c
368+
@implementation CalendarManager
369+
{
370+
bool hasListeners;
371+
}
372+
373+
// 在添加第一个监听函数时触发
374+
-(void)startObserving {
375+
hasListeners = YES;
376+
// Set up any upstream listeners or background tasks as necessary
377+
}
378+
379+
// Will be called when this module's last listener is removed, or on dealloc.
380+
-(void)stopObserving {
381+
hasListeners = NO;
382+
// Remove upstream listeners, stop unnecessary background tasks
383+
}
384+
385+
- (void)calendarEventReminderReceived:(NSNotification *)notification
386+
{
387+
NSString *eventName = notification.userInfo[@"name"];
388+
if (hasListeners) { // Only send events if anyone is listening
389+
[self sendEventWithName:@"EventReminder" body:@{@"name": eventName}];
390+
}
391+
}
392+
```
393+
380394
## 从Swift导出
381395
382396
Swift不支持宏,所以从Swift向React Native导出类和函数需要多做一些设置,但是大致与Objective-C是相同的。

docs/docs/next/text.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var styles = StyleSheet.create({
3838
</div>
3939
</div>
4040
<div class="prop">
41-
<h4 class="propTitle"><a class="anchor" name="allowfontscaling"></a><span class="platform">ios</span>allowFontScaling <span class="propType">bool</span> <a class="hash-link" href="#allowfontscaling">#</a></h4>
41+
<h4 class="propTitle"><a class="anchor" name="allowfontscaling"></a>allowFontScaling <span class="propType">bool</span> <a class="hash-link" href="#allowfontscaling">#</a></h4>
4242
<div>
4343
<p>控制字体是否要根据iOS的“文本大小”辅助选项来进行缩放。</p>
4444
</div>

0 commit comments

Comments
 (0)