Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Refactor UserProfilePictureView into UserProfile.PictureView. (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlutsenko authored Jul 27, 2016
1 parent 9688cc7 commit e41ee3a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 90 deletions.
8 changes: 4 additions & 4 deletions FacebookSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
813C9CFA1D1DBFA000288BFA /* LoginButton.Tooltip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 813C9CF91D1DBFA000288BFA /* LoginButton.Tooltip.swift */; };
815DEBCC1D024ADD000370CA /* GraphRequestProtocol.Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 815DEBCB1D024ADD000370CA /* GraphRequestProtocol.Bridge.swift */; };
816B75A71D07AEB70012AC43 /* GraphRequestDataAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 816B75A61D07AEB70012AC43 /* GraphRequestDataAttachment.swift */; };
817021AE1D18DE1500ECE7AC /* UserProfilePictureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 817021AD1D18DE1500ECE7AC /* UserProfilePictureView.swift */; };
817021AE1D18DE1500ECE7AC /* UserProfile.PictureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 817021AD1D18DE1500ECE7AC /* UserProfile.PictureView.swift */; };
817A0A0E1D07CE8A00FD423A /* GraphRequestResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 817A0A0D1D07CE8A00FD423A /* GraphRequestResult.swift */; };
81AB8A871D36D43100066F63 /* FBSDKCoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81AB8A3D1D36D41700066F63 /* FBSDKCoreKit.framework */; };
81AB8A941D36D44C00066F63 /* FBSDKCoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81AB8A3D1D36D41700066F63 /* FBSDKCoreKit.framework */; };
Expand Down Expand Up @@ -384,7 +384,7 @@
81654DD51D356E9A006401F1 /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
81654DD61D356E9A006401F1 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = "<group>"; };
816B75A61D07AEB70012AC43 /* GraphRequestDataAttachment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphRequestDataAttachment.swift; sourceTree = "<group>"; };
817021AD1D18DE1500ECE7AC /* UserProfilePictureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserProfilePictureView.swift; sourceTree = "<group>"; };
817021AD1D18DE1500ECE7AC /* UserProfile.PictureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserProfile.PictureView.swift; sourceTree = "<group>"; };
817A0A0D1D07CE8A00FD423A /* GraphRequestResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphRequestResult.swift; sourceTree = "<group>"; };
81AB8A091D36D41700066F63 /* FBSDKCoreKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = FBSDKCoreKit.xcodeproj; path = "../Carthage/Checkouts/facebook-ios-sdk/FBSDKCoreKit/FBSDKCoreKit.xcodeproj"; sourceTree = "<group>"; };
81AB8A0C1D36D41700066F63 /* FBSDKLoginKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = FBSDKLoginKit.xcodeproj; path = "../Carthage/Checkouts/facebook-ios-sdk/FBSDKLoginKit/FBSDKLoginKit.xcodeproj"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -906,7 +906,7 @@
isa = PBXGroup;
children = (
81FC4EF11D068564003F3A46 /* UserProfile.swift */,
817021AD1D18DE1500ECE7AC /* UserProfilePictureView.swift */,
817021AD1D18DE1500ECE7AC /* UserProfile.PictureView.swift */,
);
path = UserProfile;
sourceTree = "<group>";
Expand Down Expand Up @@ -1273,7 +1273,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
817021AE1D18DE1500ECE7AC /* UserProfilePictureView.swift in Sources */,
817021AE1D18DE1500ECE7AC /* UserProfile.PictureView.swift in Sources */,
810192B61D01305400B9E881 /* SDKLoggingBehavior.swift in Sources */,
81FC4CBB1D0674F4003F3A46 /* PublishPermission.swift in Sources */,
810192B51D01305400B9E881 /* ApplicationDelegate.swift in Sources */,
Expand Down
90 changes: 90 additions & 0 deletions Sources/Core/UserProfile/UserProfile.PictureView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
//
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
// copy, modify, and distribute this software in source code or binary form for use
// in connection with the web services and APIs provided by Facebook.
//
// As with any software that integrates with the Facebook platform, your use of
// this software is subject to the Facebook Developer Principles and Policies
// [http://developers.facebook.com/policy/]. This copyright notice shall be
// included in all copies or substantial portions of the software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import Foundation
import UIKit

import FBSDKCoreKit.FBSDKProfilePictureView

extension UserProfile {

/// A view to display a profile picture.
public class PictureView: UIView {

private let sdkProfilePictureView = FBSDKProfilePictureView(frame: .zero)

/// The aspect ratio of the source image of the profile picture.
public var pictureAspectRatio = UserProfile.PictureAspectRatio.Square {
didSet {
sdkProfilePictureView.pictureMode = pictureAspectRatio.sdkPictureMode
}
}

/// The user id to show the picture for.
public var userId = "me" {
didSet {
sdkProfilePictureView.profileID = userId
}
}

/**
Create a new instance of `UserProfilePictureView`.
- parameter frame: Optional frame rectangle for the view, measured in points.
- parameter profile: Optional profile to display a picture for. Default: `UserProfile.current`.
*/
public init(frame: CGRect = .zero, profile: UserProfile? = nil) {
super.init(frame: frame)

if let profile = profile {
userId = profile.userId
}
setupSDKProfilePictureView()
}

/**
Create a new instance of `UserProfilePictureView` from an encoded interface file.
- parameter decoder: The coder to initialize from.
*/
public required init?(coder decoder: NSCoder) {
super.init(coder: decoder)
setupSDKProfilePictureView()
}

/**
Explicitly marks the receiver as needing to update the image.
This method is called whenever any properties that affect the source image are modified,
but this can also be used to trigger a manual update of the image if it needs to be re-downloaded.
*/
public func setNeedsImageUpdate() {
sdkProfilePictureView.setNeedsImageUpdate()
}
}
}

extension UserProfile.PictureView {

private func setupSDKProfilePictureView() {
sdkProfilePictureView.frame = bounds
sdkProfilePictureView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
addSubview(sdkProfilePictureView)
setNeedsImageUpdate() // Trigger the update to refresh the image, just in case.
}
}
86 changes: 0 additions & 86 deletions Sources/Core/UserProfile/UserProfilePictureView.swift

This file was deleted.

0 comments on commit e41ee3a

Please sign in to comment.