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

Commit 6e6cb8c

Browse files
authored
Merge pull request #883 from artsy/sos-home-select-tab-from-props
[home] adds a way to select tab from initial props
2 parents 84d18a3 + d886b5a commit 6e6cb8c

File tree

8 files changed

+28
-6
lines changed

8 files changed

+28
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
### Master
55

6+
- Adds a way to select tab on Home scene from initial props - sarah
67
- Don't load an ArtistRail if it doesn't have any artists - sarah
78
- Refetch data when user re-enters Inbox tab - luc
89
- Send event from view controller to react component when tab changes - luc

Example/Emission/ARRootViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ - (ARCellData *)jumpToRandomArtist
169169
- (ARCellData *)jumpToHomepage
170170
{
171171
return [self tappableCellDataWithTitle:@"Homepage" selection: ^{
172-
id viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:nil emission:nil];
172+
id viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:nil tab:0 emission:nil];
173173
[self.navigationController pushViewController:viewController animated:YES];
174174
}];
175175
}

Example/Emission/AppDelegate.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ - (UIViewController *)viewControllerForRoute:(NSString *)route;
234234
NSString *conversationID = [[route componentsSeparatedByString:@"/"] lastObject];
235235
viewController = [[ARConversationComponentViewController alloc] initWithConversationID:conversationID];
236236
} else if ([route isEqualToString:@"/"]) {
237-
viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:nil emission:nil];
237+
viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:nil tab:0 emission:nil];
238238

239239
} else if ([route hasPrefix:@"/works-for-you/"] || [route hasPrefix:@"works-for-you"]) {
240240
NSURLComponents *components = [[NSURLComponents alloc] initWithString:route];
241241
NSString *artistID = [self valueForKey:@"artist_id" fromQueryItems:components.queryItems];
242-
viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:artistID emission:nil];
242+
viewController = [[ARHomeComponentViewController alloc] initWithSelectedArtist:artistID tab:0 emission:nil];
243243

244244
} else {
245245

Example/Podfile

+17
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,26 @@ target 'Emission' do
4646
:branch => 'fetch-user-details'
4747
end
4848

49+
def edit_pod_file(file, old_code, new_code)
50+
code = File.read(file)
51+
if code.include?(old_code)
52+
FileUtils.chmod("+w", file)
53+
File.write(file, code.sub(old_code, new_code))
54+
end
55+
end
56+
4957
post_install do |installer|
5058
emission = installer.pods_project.targets.find { |target| target.name == 'Emission' }
5159
emission.build_configurations.each do |config|
5260
config.build_settings['GCC_TREAT_WARNINGS_AS_ERRORS'] = "YES"
5361
end
62+
63+
# This fixes a bug in our Home tab view; it can probably be removed when we upgrade to RN 0.50+
64+
# See https://github.com/artsy/collector-experience/issues/751
65+
react_scrollview_file = '../node_modules/react-native/React/Views/RCTScrollView.m'
66+
react_scrollview_old_code = 'self.contentOffset = CGPointMake(
67+
MAX(0, MIN(originalOffset.x, fullContentSize.width - boundsSize.width)),
68+
MAX(0, MIN(originalOffset.y, fullContentSize.height - boundsSize.height)));'
69+
react_scrollview_new_code = 'self.contentOffset= originalOffset;'
70+
edit_pod_file react_scrollview_file, react_scrollview_old_code, react_scrollview_new_code
5471
end

Example/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,6 @@ SPEC CHECKSUMS:
160160
UIView+BooleanAnimations: a760be9a066036e55f298b7b7350a6cb14cfcd97
161161
Yoga: ccefa1454b2e9825dce3b2df98088b7f0e3c2675
162162

163-
PODFILE CHECKSUM: a2917583e92ba6e19fd0ab3e8e61f7125467542c
163+
PODFILE CHECKSUM: 867e9da9d8ae434ba0d256bf464f2054a0f7ca51
164164

165165
COCOAPODS: 1.3.1

Pod/Classes/ViewControllers/ARHomeComponentViewController.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ NS_ASSUME_NONNULL_BEGIN
77
@property (nonatomic, strong, readonly) NSString *selectedArtist;
88

99
- (instancetype)initWithSelectedArtist:(nullable NSString *)artistID
10+
tab:(NSInteger)selectedTab
1011
emission:(nullable AREmission*)emission NS_DESIGNATED_INITIALIZER;
1112

1213

Pod/Classes/ViewControllers/ARHomeComponentViewController.m

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
@implementation ARHomeComponentViewController
55

6-
- (instancetype)initWithSelectedArtist:(NSString *)artistID emission:(AREmission *)emission;
6+
- (instancetype)initWithSelectedArtist:(nullable NSString *)artistID tab:(NSInteger)selectedTab emission:(nullable AREmission*)emission;
77
{
8+
NSDictionary *initialProps = artistID ? @{ @"selectedArtist": artistID, @"selectedTab": @(selectedTab) } : @{ @"selectedTab": @(selectedTab) };
89
if ((self = [super initWithEmission:emission
910
moduleName:@"Home"
10-
initialProperties:artistID ? @{ @"selectedArtist": artistID } : nil])) {
11+
initialProperties:initialProps])) {
1112
_selectedArtist = artistID;
1213
}
1314
return self;

src/lib/Scenes/Home/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ const TabBarContainer = styled.View`margin-top: 20px;`
2121

2222
interface Props {
2323
selectedArtist?: string
24+
selectedTab?: number
2425
}
2526

2627
export default class Home extends React.Component<Props, null> {
2728
render() {
2829
return (
2930
<View style={{ flex: 1 }}>
3031
<ScrollableTabView
32+
initialPage={this.props.selectedTab || 0}
3133
renderTabBar={props =>
3234
<TabBarContainer>
3335
<TabBar {...props} />

0 commit comments

Comments
 (0)