Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode 8 + Swift 3 #24

Merged
merged 1 commit into from
Sep 21, 2016
Merged

Xcode 8 + Swift 3 #24

merged 1 commit into from
Sep 21, 2016

Conversation

mohpor
Copy link
Contributor

@mohpor mohpor commented Sep 14, 2016

No description provided.

@mohpor
Copy link
Contributor Author

mohpor commented Sep 14, 2016

Some notes:

I have tested the framework locally on my computer and again on my devices, ran the test and everything went fine, all tests' passed. Except, when actually testing it on device, the TwitterBot example would crash upon displaying the action sheet, complaining about internal inconsistency with number of rows and the data set.

It's worth taking a look.

Copy link
Member

@m-revetria m-revetria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohpor thanks for updating your PR. I just finished reviewing it and I left some minor comments.

I think that the crash in the Tweetbot example is caused by a wrong value returned in the function collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int. Check out my comment about it for more datils

if hasHeader() && section == 0 { return 0 }
if settings.behavior.useDynamics && section > _dynamicSectionIndex {
if settings.behavior.useDynamics && section > _dynamicSectionIndex ?? 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not exactly the same, now if _dynamicSectionIndex is null and section is 0, then this function si returning _sections[actionSectionIndexFor(section)].actions.count. While previously it returned 0.

Additionally, this is causing the crash that you saw. When _dynamicSectionIndex is null, it means that no data has been added to the collection view (in the case useDynamics==true). So the collection view datasource is returning x number of rows for section 0 when no one has been inserted.

Next code should be fix the crash:

    open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if hasHeader() && section == 0 { return 0 }
        let rows = _sections[actionSectionIndexFor(section)].actions.count

        guard let dynamicSectionIndex = _dynamicSectionIndex else {
            return settings.behavior.useDynamics ? 0 : rows
        }
        if settings.behavior.useDynamics && section > dynamicSectionIndex {
            return 0
        }
        return rows
    }

let action = self.actionForIndexPath(actionIndexPathFor(indexPath))

if let action = action where action.executeImmediatelyOnTouch {
if let action = action , action.executeImmediatelyOnTouch {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the white space before the comma

cell.alpha = action.enabled ? 1.0 : 0.5
}
}

required public init?(coder aDecoder: NSCoder) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please indent using 4 spaces


onConfigureCellForAction = { cell, action, indexPath in
cell.setup(action.data?.title, detail: action.data?.subtitle, image: action.data?.image)
cell.alpha = action.enabled ? 1.0 : 0.5

UIView.animateWithDuration(0.30) {
UIView.animate(withDuration: 0.30) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix indentation

Copy link
Contributor Author

@mohpor mohpor Sep 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, But I fail to see the point of an empty animation block! Did you mean to put that alpha value change inside the animation block?

}
}

view.addSubview(collectionView)

// calculate content Inset
collectionView.layoutSubviews()
if let section = _sections.last where !settings.behavior.useDynamics {
if let section = _sections.last , !settings.behavior.useDynamics {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please delete white space before comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is caused by the Xcode migrator tool which replaced where with , (Notice that there is a whitespace before and after where but there shouldn't be white space there. I shouldn't have overlooked these. Sorry)

super.viewDidLayoutSubviews()
collectionView.collectionViewLayout.invalidateLayout()
}

public override func prefersStatusBarHidden() -> Bool {
open override var prefersStatusBarHidden : Bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please delete white space before colon

return !settings.statusBar.showStatusBar
}

public override func preferredStatusBarStyle() -> UIStatusBarStyle {
open override var preferredStatusBarStyle : UIStatusBarStyle {
Copy link
Member

@m-revetria m-revetria Sep 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too and please remove extra space between open and override

action.handler?(action)
}

self.dismiss() {
if let action = action where !action.executeImmediatelyOnTouch {
if let action = action , !action.executeImmediatelyOnTouch {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove space before comma

@gchristov
Copy link

Just noticed this PR and was wondering if it will get merged in at some point? This is the relevant issue for this #25

@ryanholden8
Copy link

Looking forward to the merge, great work!

@thonydam
Copy link

👍

@mohpor
Copy link
Contributor Author

mohpor commented Sep 17, 2016

@m-revetria, I have rebased the PR based on your comments.
The error has been fixed for TwitterBot example thanks to the code you've provided.
(Honestly, I have converted so many Libraries to Swift 3 in the past couple of weeks, my mind's playing tricks on me and makes me do stupid things like coercing nulls into 0! sorry about that)

@m-revetria m-revetria merged commit 9e83f9c into xmartlabs:master Sep 21, 2016
@m-revetria
Copy link
Member

@mohpor great work! thanks for your help and your time updating this PR!

@mohpor mohpor deleted the Swift3-Release branch September 22, 2016 05:17
@mohpor mohpor mentioned this pull request Sep 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants