mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-27 19:25:11 +08:00
Replaced isMainThread checks with a proper test for main queue
Summary: As per https://twitter.com/olebegemann/status/738656134731599872, our use of "main thread" to mean "main queue" seems to be unsafe. This diff replaces the `NSThread.isMainQueue` checks with dispatch_get_specific(), which is the recommended approach. I've also replaced all use of "MainThread" terminology with "MainQueue", and taken the opportunity to deprecate the "sync" param of `RCTExecuteOnMainThread()`, which, while we do still use it in a few places, is incredibly unsafe and shouldn't be encouraged. Reviewed By: javache Differential Revision: D3384910 fbshipit-source-id: ea7c216013372267b82eb25a38db5eb4cd46a089
This commit is contained in:
committed by
Facebook Github Bot 6
parent
1048e5d344
commit
72b363d7fc
@@ -271,7 +271,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
modifierFlags:(UIKeyModifierFlags)flags
|
||||
action:(void (^)(UIKeyCommand *))block
|
||||
{
|
||||
RCTAssertMainThread();
|
||||
RCTAssertMainQueue();
|
||||
|
||||
if (input.length && flags && RCTIsIOS8OrEarlier()) {
|
||||
|
||||
@@ -296,7 +296,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
- (void)unregisterKeyCommandWithInput:(NSString *)input
|
||||
modifierFlags:(UIKeyModifierFlags)flags
|
||||
{
|
||||
RCTAssertMainThread();
|
||||
RCTAssertMainQueue();
|
||||
|
||||
for (RCTKeyCommand *command in _commands.allObjects) {
|
||||
if ([command matchesInput:input flags:flags]) {
|
||||
@@ -309,7 +309,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
- (BOOL)isKeyCommandRegisteredForInput:(NSString *)input
|
||||
modifierFlags:(UIKeyModifierFlags)flags
|
||||
{
|
||||
RCTAssertMainThread();
|
||||
RCTAssertMainQueue();
|
||||
|
||||
for (RCTKeyCommand *command in _commands) {
|
||||
if ([command matchesInput:input flags:flags]) {
|
||||
@@ -323,7 +323,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
modifierFlags:(UIKeyModifierFlags)flags
|
||||
action:(void (^)(UIKeyCommand *))block
|
||||
{
|
||||
RCTAssertMainThread();
|
||||
RCTAssertMainQueue();
|
||||
|
||||
if (input.length && flags && RCTIsIOS8OrEarlier()) {
|
||||
|
||||
@@ -348,7 +348,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
- (void)unregisterDoublePressKeyCommandWithInput:(NSString *)input
|
||||
modifierFlags:(UIKeyModifierFlags)flags
|
||||
{
|
||||
RCTAssertMainThread();
|
||||
RCTAssertMainQueue();
|
||||
|
||||
for (RCTKeyCommand *command in _commands.allObjects) {
|
||||
if ([command matchesInput:input flags:flags]) {
|
||||
@@ -361,7 +361,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
- (BOOL)isDoublePressKeyCommandRegisteredForInput:(NSString *)input
|
||||
modifierFlags:(UIKeyModifierFlags)flags
|
||||
{
|
||||
RCTAssertMainThread();
|
||||
RCTAssertMainQueue();
|
||||
|
||||
for (RCTKeyCommand *command in _commands) {
|
||||
if ([command matchesInput:input flags:flags]) {
|
||||
|
||||
Reference in New Issue
Block a user