From 091213d31148a9bd0e2b103eec3805a8df7cff48 Mon Sep 17 00:00:00 2001 From: Sarah Scott Date: Mon, 11 Dec 2017 17:08:01 -0500 Subject: [PATCH] [home] adds a way to select tab from initial props --- CHANGELOG.md | 1 + Example/Emission/ARRootViewController.m | 2 +- Example/Emission/AppDelegate.m | 4 ++-- Example/Podfile | 17 +++++++++++++++++ Example/Podfile.lock | 2 +- .../ARHomeComponentViewController.h | 1 + .../ARHomeComponentViewController.m | 5 +++-- src/lib/Scenes/Home/index.tsx | 2 ++ 8 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd80763a4f..a7c8e3b6b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Master +- Adds a way to select tab on Home scene from initial props - sarah - Refetch data when user re-enters Inbox tab - luc - Send event from view controller to react component when tab changes - luc - Allow passing a set of Artworks and an index to load to Eigen when clicking on diff --git a/Example/Emission/ARRootViewController.m b/Example/Emission/ARRootViewController.m index 170b10b688..fd5c90ab91 100644 --- a/Example/Emission/ARRootViewController.m +++ b/Example/Emission/ARRootViewController.m @@ -169,7 +169,7 @@ - (ARCellData *)jumpToRandomArtist - (ARCellData *)jumpToHomepage { return [self tappableCellDataWithTitle:@"Homepage" selection: ^{ - id viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:nil emission:nil]; + id viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:nil tab:0 emission:nil]; [self.navigationController pushViewController:viewController animated:YES]; }]; } diff --git a/Example/Emission/AppDelegate.m b/Example/Emission/AppDelegate.m index 080c6e3f0a..c506e4b8f4 100644 --- a/Example/Emission/AppDelegate.m +++ b/Example/Emission/AppDelegate.m @@ -234,12 +234,12 @@ - (UIViewController *)viewControllerForRoute:(NSString *)route; NSString *conversationID = [[route componentsSeparatedByString:@"/"] lastObject]; viewController = [[ARConversationComponentViewController alloc] initWithConversationID:conversationID]; } else if ([route isEqualToString:@"/"]) { - viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:nil emission:nil]; + viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:nil tab:0 emission:nil]; } else if ([route hasPrefix:@"/works-for-you/"] || [route hasPrefix:@"works-for-you"]) { NSURLComponents *components = [[NSURLComponents alloc] initWithString:route]; NSString *artistID = [self valueForKey:@"artist_id" fromQueryItems:components.queryItems]; - viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:artistID emission:nil]; + viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:artistID tab:0 emission:nil]; } else { diff --git a/Example/Podfile b/Example/Podfile index b618717633..47a1f956ae 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -46,9 +46,26 @@ target 'Emission' do :branch => 'fetch-user-details' end +def edit_pod_file(file, old_code, new_code) + code = File.read(file) + if code.include?(old_code) + FileUtils.chmod("+w", file) + File.write(file, code.sub(old_code, new_code)) + end +end + post_install do |installer| emission = installer.pods_project.targets.find { |target| target.name == 'Emission' } emission.build_configurations.each do |config| config.build_settings['GCC_TREAT_WARNINGS_AS_ERRORS'] = "YES" end + + # This fixes a bug in our Home tab view; it can probably be removed when we upgrade to RN 0.50+ + # See https://github.com/artsy/collector-experience/issues/751 + react_scrollview_file = '../node_modules/react-native/React/Views/RCTScrollView.m' + react_scrollview_old_code = 'self.contentOffset = CGPointMake( + MAX(0, MIN(originalOffset.x, fullContentSize.width - boundsSize.width)), + MAX(0, MIN(originalOffset.y, fullContentSize.height - boundsSize.height)));' + react_scrollview_new_code = 'self.contentOffset= originalOffset;' + edit_pod_file react_scrollview_file, react_scrollview_old_code, react_scrollview_new_code end diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 9721cf604c..183337b990 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -160,6 +160,6 @@ SPEC CHECKSUMS: UIView+BooleanAnimations: a760be9a066036e55f298b7b7350a6cb14cfcd97 Yoga: ccefa1454b2e9825dce3b2df98088b7f0e3c2675 -PODFILE CHECKSUM: a2917583e92ba6e19fd0ab3e8e61f7125467542c +PODFILE CHECKSUM: 867e9da9d8ae434ba0d256bf464f2054a0f7ca51 COCOAPODS: 1.3.1 diff --git a/Pod/Classes/ViewControllers/ARHomeComponentViewController.h b/Pod/Classes/ViewControllers/ARHomeComponentViewController.h index 5746be4133..64423b45e4 100644 --- a/Pod/Classes/ViewControllers/ARHomeComponentViewController.h +++ b/Pod/Classes/ViewControllers/ARHomeComponentViewController.h @@ -7,6 +7,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, readonly) NSString *selectedArtist; - (instancetype)initWithSelectedArtist:(nullable NSString *)artistID + tab:(NSInteger)selectedTab emission:(nullable AREmission*)emission NS_DESIGNATED_INITIALIZER; diff --git a/Pod/Classes/ViewControllers/ARHomeComponentViewController.m b/Pod/Classes/ViewControllers/ARHomeComponentViewController.m index cea7c7b3d5..e838d63077 100644 --- a/Pod/Classes/ViewControllers/ARHomeComponentViewController.m +++ b/Pod/Classes/ViewControllers/ARHomeComponentViewController.m @@ -3,11 +3,12 @@ @implementation ARHomeComponentViewController -- (instancetype)initWithSelectedArtist:(NSString *)artistID emission:(AREmission *)emission; +- (instancetype)initWithSelectedArtist:(nullable NSString *)artistID tab:(NSInteger)selectedTab emission:(nullable AREmission*)emission; { + NSDictionary *initialProps = artistID ? @{ @"selectedArtist": artistID, @"selectedTab": @(selectedTab) } : @{ @"selectedTab": @(selectedTab) }; if ((self = [super initWithEmission:emission moduleName:@"Home" - initialProperties:artistID ? @{ @"selectedArtist": artistID } : nil])) { + initialProperties:initialProps])) { _selectedArtist = artistID; } return self; diff --git a/src/lib/Scenes/Home/index.tsx b/src/lib/Scenes/Home/index.tsx index a181c32ed4..805ee8c5ae 100644 --- a/src/lib/Scenes/Home/index.tsx +++ b/src/lib/Scenes/Home/index.tsx @@ -21,6 +21,7 @@ const TabBarContainer = styled.View`margin-top: 20px;` interface Props { selectedArtist?: string + selectedTab?: number } export default class Home extends React.Component { @@ -28,6 +29,7 @@ export default class Home extends React.Component { return (