Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #883 from artsy/sos-home-select-tab-from-props
Browse files Browse the repository at this point in the history
[home] adds a way to select tab from initial props
  • Loading branch information
alloy authored Dec 12, 2017
2 parents 84d18a3 + d886b5a commit 6e6cb8c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Master

- Adds a way to select tab on Home scene from initial props - sarah
- Don't load an ArtistRail if it doesn't have any artists - sarah
- Refetch data when user re-enters Inbox tab - luc
- Send event from view controller to react component when tab changes - luc
Expand Down
2 changes: 1 addition & 1 deletion Example/Emission/ARRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}];
}
Expand Down
4 changes: 2 additions & 2 deletions Example/Emission/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
17 changes: 17 additions & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ SPEC CHECKSUMS:
UIView+BooleanAnimations: a760be9a066036e55f298b7b7350a6cb14cfcd97
Yoga: ccefa1454b2e9825dce3b2df98088b7f0e3c2675

PODFILE CHECKSUM: a2917583e92ba6e19fd0ab3e8e61f7125467542c
PODFILE CHECKSUM: 867e9da9d8ae434ba0d256bf464f2054a0f7ca51

COCOAPODS: 1.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
5 changes: 3 additions & 2 deletions Pod/Classes/ViewControllers/ARHomeComponentViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/lib/Scenes/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const TabBarContainer = styled.View`margin-top: 20px;`

interface Props {
selectedArtist?: string
selectedTab?: number
}

export default class Home extends React.Component<Props, null> {
render() {
return (
<View style={{ flex: 1 }}>
<ScrollableTabView
initialPage={this.props.selectedTab || 0}
renderTabBar={props =>
<TabBarContainer>
<TabBar {...props} />
Expand Down

0 comments on commit 6e6cb8c

Please sign in to comment.