Swiftpack.co -  estampworld/tweetview-ios as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
estampworld/tweetview-ios
Display Tweet Views
.package(url: "https://github.com/estampworld/tweetview-ios.git", from: "1.0.0")

TweetView

TweetView CI codebeat badge

Display a Tweet in a TweetView using the Tweet's id.

Features

Install

Swift Package Manager

Adding it to an existent iOS Project via Swift Package Manager

Usage

Swift

Creating a Tweet View


TweetView.prepare()

let width = view.frame.width - 32.0

let tweetView = TweetView(id:"1345021162959503360")

tweetView.frame = CGRect(x: 16, y: 16, width: width, height: width)
tweetView.delegate = self

self.view.addSubview(tweetView)

tweetView.load()

Delegate

extension ...: TweetViewDelegate {
    func tweetView(_ tweetView: TweetView, didUpdatedHeight height: CGFloat) {
        tweetView.frame.size = CGSize(width: tweetView.frame.width, height: height)
    }

    func tweetView(_ tweetView: TweetView, shouldOpenURL url: URL) {
    }
}

SwiftUI

struct SwiftUITweetView: View {
    @State var id: String
    @State var height: CGFloat = 200

    var body: some View {
        TweetViewAdapter(id: $id, height: $height)
            .frame(minWidth: 0, maxWidth: .infinity, minHeight: height, maxHeight: .infinity)
    }
}

struct TweetViewAdapter: UIViewRepresentable {
    @Binding var id: String
    @Binding var height: CGFloat

    func makeCoordinator() -> Coordinator {
        return Coordinator(height: $height)
    }

    func makeUIView(context: Context) -> TweetView {
        TweetView.prepare()
        let tweetView = TweetView(id: id)
        tweetView.delegate = context.coordinator
        tweetView.load()
        return tweetView
    }

    func updateUIView(_ uiView: TweetView, context: Context) {
    }
}

class Coordinator: NSObject, TweetViewDelegate {
    @Binding var updatedHeight: CGFloat

    init(height: Binding<CGFloat>) {
        _updatedHeight = height
    }

    func tweetView(_ tweetView: TweetView, didUpdatedHeight height: CGFloat) {
        tweetView.frame.size = CGSize(width: tweetView.frame.width, height: height)
        updatedHeight = height
    }

    func tweetView(_ tweetView: TweetView, shouldOpenURL url: URL) {
    }
}

Based on

https://blog.twitter.com/developer/en_us/topics/tips/2019/displaying-tweets-in-ios-apps.html

Maintainers

Eduardo Irias, creator.

Leigh Stewart

Contributing

  1. Fork it ( https://github.com/estampworld/tweetview-ios/fork )
  2. Create your feature branch (git checkout -b feature/[my-new-feature])
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/[my-new-feature])
  5. Create a new Pull Request

License

Toast Alert Views is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 5
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

1.0.0 Initial Release
27 weeks ago

୧☉□☉୨

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API