Skip to content

Load images from framework bundle #20

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AsyncMessagesViewController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |spec|
spec.swift_version = '4.0'
spec.requires_arc = true
spec.source_files = 'Source/**/*.swift'
spec.ios.resource_bundle = { spec => 'Source/Assets/AsyncMessagesViewController.xcassets' }
spec.ios.resource_bundle = { 'AsyncMessagesViewController' => 'Source/Assets/AsyncMessagesViewController.xcassets' }
spec.dependency 'Texture', '2.6'
spec.dependency 'SlackTextViewController', '1.9.6'
end
13 changes: 11 additions & 2 deletions Source/Controllers/MessageBubbleImageProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ open class MessageBubbleImageProvider {
private let outgoingColor: UIColor
private let incomingColor: UIColor
private var imageCache = [MessageProperties: UIImage]()


// This resource bundle name must match with the on declare in podspec
// For example:
// spec.ios.resource_bundle = { 'AsyncMessagesViewController' => 'Source/Assets/AsyncMessagesViewController.xcassets' }
// Credit: https://stackoverflow.com/questions/35692265/how-to-load-resource-in-cocoapods-resource-bundle/35903720
private static let RESOURCE_BUNDLE_NAME = "AsyncMessagesViewController.bundle"

public init(incomingColor: UIColor = kDefaultIncomingColor, outgoingColor: UIColor = kDefaultOutgoingColor) {
self.incomingColor = incomingColor
self.outgoingColor = outgoingColor
Expand All @@ -51,8 +57,11 @@ open class MessageBubbleImageProvider {
}

private func buildBubbleImage(properties: MessageProperties) -> UIImage {
let bundle = Bundle(for: MessageBubbleImageProvider.self)
let resourceBundleUrl = bundle.resourceURL?.appendingPathComponent(MessageBubbleImageProvider.RESOURCE_BUNDLE_NAME)
let resourceBundle = Bundle(url: resourceBundleUrl!)
let imageName = "bubble" + (properties.isOutgoing ? "_outgoing" : "_incoming") + (properties.hasTail ? "" : "_tailless")
let bubble = UIImage(named: imageName)!
let bubble = UIImage(named: imageName, in: resourceBundle, compatibleWith: nil)!

do {
var normalBubble = try bubble.imageMaskedWith(color: properties.isOutgoing ? outgoingColor : incomingColor)
Expand Down