Skip to content

Commit

Permalink
Updated code and example for RN 0.26+, fixes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanregisser committed May 27, 2016
1 parent f94f026 commit a9c1601
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 21 deletions.
10 changes: 8 additions & 2 deletions Example/PopoverExample.xcodeproj/project.pbxproj
Expand Up @@ -628,7 +628,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/iOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
);
PRODUCT_NAME = PopoverExample;
};
name = Debug;
Expand All @@ -639,7 +642,10 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/iOS/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_LDFLAGS = "-ObjC";
OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
);
PRODUCT_NAME = PopoverExample;
};
name = Release;
Expand Down
28 changes: 15 additions & 13 deletions Example/PopoverExampleTests/PopoverExampleTests.m
Expand Up @@ -10,8 +10,7 @@
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>

#import "RCTAssert.h"
#import "RCTRedBox.h"
#import "RCTLog.h"
#import "RCTRootView.h"

#define TIMEOUT_SECONDS 240
Expand All @@ -23,7 +22,6 @@ @interface PopoverExampleTests : XCTestCase

@implementation PopoverExampleTests


- (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
{
if (test(view)) {
Expand All @@ -37,31 +35,35 @@ - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test
return NO;
}

- (void)testRendersWelcomeScreen {
- (void)testRendersWelcomeScreen
{
UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS];
BOOL foundElement = NO;
NSString *redboxError = nil;

__block NSString *redboxError = nil;
RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) {
if (level >= RCTLogLevelError) {
redboxError = message;
}
});

while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) {
[[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
[[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];

redboxError = [[RCTRedBox sharedInstance] currentErrorMessage];

foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) {
if ([view respondsToSelector:@selector(attributedText)]) {
NSString *text = [(id)view attributedText].string;
if ([text isEqualToString:TEXT_TO_LOOK_FOR]) {
return YES;
}
if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) {
return YES;
}
return NO;
}];
}

RCTSetLogFunction(RCTDefaultLogFunction);

XCTAssertNil(redboxError, @"RedBox error: %@", redboxError);
XCTAssertTrue(foundElement, @"Cound't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS);
}


Expand Down
1 change: 1 addition & 0 deletions Example/iOS/AppDelegate.m
Expand Up @@ -47,6 +47,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"PopoverExample"
initialProperties:nil
launchOptions:launchOptions];

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
Expand Down
5 changes: 5 additions & 0 deletions Example/iOS/Info.plist
Expand Up @@ -38,5 +38,10 @@
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
4 changes: 2 additions & 2 deletions Example/index.ios.js
@@ -1,6 +1,6 @@
'use strict';

var React = require('react-native');
var React = require('react');
var Popover = require('../Popover');
var {
AppRegistry,
Expand All @@ -9,7 +9,7 @@ var {
Text,
TouchableHighlight,
View,
} = React;
} = require('react-native');

var PopoverExample = React.createClass({
getInitialState() {
Expand Down
8 changes: 4 additions & 4 deletions Popover.js
@@ -1,16 +1,16 @@
'use strict';

var React = require('react-native');
var {
PropTypes,
import React, { PropTypes } from 'react';
import {
StyleSheet,
Dimensions,
Animated,
Text,
TouchableWithoutFeedback,
View,
Easing
} = React;
} from 'react-native';

var noop = () => {};

var {height: SCREEN_HEIGHT, width: SCREEN_WIDTH} = Dimensions.get('window');
Expand Down
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -20,5 +20,8 @@
"type": "git",
"url": "git@github.com:jeanregisser/react-native-popover.git"
},
"devDependencies": {
"react": "^15.0.2",
"react-native": "^0.26.2"
}
}

0 comments on commit a9c1601

Please sign in to comment.