GithubHelp home page GithubHelp logo

twitter / twittertexteditor Goto Github PK

View Code? Open in Web Editor NEW
3.0K 48.0 161.0 730 KB

A standalone, flexible API that provides a full-featured rich text editor for iOS applications.

License: Apache License 2.0

Ruby 1.85% Makefile 1.55% Swift 96.61%
ios uikit swift textkit

twittertexteditor's Introduction

Twitter Text Editor

A standalone, flexible API that provides a full featured rich text editor for iOS applications.

Twitter Text Editor

It supports safe text modification, attribute annotations such as syntax highlighting, pasting or drag and drop handling.

This provides a robust text attribute update logic, extended text editing events, and safe text input event handling in easy delegate based APIs. TwitterTextEditor supports recent versions of iOS.

Requirements

Twitter Text Editor requires macOS Catalina 10.15 or later and Xcode 11.0 and later for the development. At this moment, Twitter Text Editor supports iOS 11.0 and later also macCatalyst 13.0 and later.

Usage

Using Twitter Text Editor is straightforward if you're familiar with iOS development. See also Examples for actual usage, that contains Swift and Objective-C source code to show how to use Twitter Text Editor. See Examples/README.md as well.

Add Twitter Text Editor framework to your project

Add the following lines to your Package.swift or use Xcode “Add Package Dependency…” menu.

// In your `Package.swift`

dependencies: [
    .package(name: "TwitterTextEditor", url: "https://github.com/twitter/TwitterTextEditor", ...),
    ...
],
targets: [
    .target(
        name: ...,
        dependencies: [
            .product(name: "TwitterTextEditor", package: "TwitterTextEditor"),
            ...
        ]
    ),
    ...
]

Use with other dependency management tools

In case your project is not using Swift Package Manager, you can use Twitter Text Editor with other dependency management tools.

CocoaPods

To use Twitter Text Editor with CocoaPods, add next TwitterTextEditor.podspec in your project.

Pod::Spec.new do |spec|
  spec.name = "TwitterTextEditor"
  spec.version = "1.0.0" # Find the the version from the Git tags
  spec.authors = ""
  spec.summary = "TwitterTextEditor"
  spec.homepage = "https://github.com/twitter/TwitterTextEditor"
  spec.platform = :ios, "11.0"
  spec.source = {
    :git => "https://github.com/twitter/TwitterTextEditor.git", :tag => "#{spec.version}"
  }
  spec.source_files  = "Sources/TwitterTextEditor/*.swift"
end

Then, update Podfile in your project.

pod 'TwitterTextEditor', :podspec => 'path/to/TwitterTextEditor.podspec'

Carthage

To use Twitter Text Editor with Carthage, update Cartfile in your project.

github "twitter/TwitterTextEditor"

Then, run following commands. This will create Carthage/Build/iOS/TwitterTextEditor.framework.

$ carthage update
$ (cd Carthage/Checkouts/TwitterTextEditor && swift package generate-xcodeproj)
$ carthage build --platform iOS

Follow the instructions to add the framework and Run Script phase to your project.

Documentation

See documentation.

Use Twitter Text Editor in your project

Twitter Text Editor provides a single view, TextEditorView, that has a similar API to UITextView and provides the most of features as a property or a delegate callback.

Add it to your project as like the other views, and setup using each property or implement delegate callbacks.

// In your view controller

import TwitterTextEditor

final class MyViewController: UIViewController {
    // ...

    override func viewDidLoad() {
        super.viewDidLoad()
        // ...
        let textEditorView = TextEditorView()
        textEditorView.text = "Meow"
        textEditorView.textAttributesDelegate = self
        // ...
    }

    // ...
}

extension MyViewController: TextEditorViewTextAttributesDelegate {
    func textEditorView(_ textEditorView: TextEditorView,
                        updateAttributedString attributedString: NSAttributedString,
                        completion: @escaping (NSAttributedString?) -> Void)
    {
        // ...
    }
}

Contributing

See CONTRIBUTING.md for the details.

Security issues

Please report sensitive security issues via Twitter’s bug-bounty program rather than GitHub.

twittertexteditor's People

Contributors

cweider avatar griffin-stewie avatar kylebshr avatar mainasuk avatar niw avatar redryerye avatar tarunon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

twittertexteditor's Issues

Discard the paste text

Hello,

we paste 1500 character and again paste same number of character. Can we discard last paste characters?

Thanks in adavnce.

One line summary of the issue

Describe the details of the issue.

Steps to reproduce the behavior

  • List all relevant steps to reproduce the observed behavior.

Expected behavior

As concisely as possible, describe the expected behavior.

Actual behavior

As concisely as possible, describe the observed behavior.

Environment

  • Operating system name, version, and build number, such as “iOS 14.0.1 (18A393)”.
  • Hardware name and revision, such as “iPhone 11 Pro”.
  • Xcode version and build number, such as “12.0 (12A7209)”.
  • Any other dependencies, such as third-party keyboard and its version, if it’s applicable.

Stop typing from keyboard

Hello,

How to stop typing from keyboard?

We have limit to stop typing from particular limit like 1500 character.

Thanks in advance.

UITextViewDelegate-like functionality?

Question

UITextViewDelegate allows you to control whether the user's edits take effect through textView(_:shouldChangeTextIn:replacementText:). I can find no replacement for TwitterTextEditor. The closest I can find is TextEditorViewEditingContentDelegate's textEditorView(_:updateEditingContent) method, but returning nil from that method doesn't seem to have the affect I want (not applying the change). It seems like I should be able to create my own editing content, but there are no types which publicly conform to TextEditorViewEditingContent. Am I supposed to create my own conforming type? In any case, it seems like this functionality should be simpler.

The SwiftUI story/relation of this library

This library was just released and while it looks interesting, many people are currently in the process of switching to SwiftUI and figuring out how things should/could be done in a SwiftUI world. While UIKit will be around for a while, I think it would be great to also add an official wrapper for the TwitterTextEditor with proper bindings and well thought through API also for SwiftUI alongside documentation examples and tests. It might still be "UIKit-first" as it was obviously designed with that in mind, but I would appreciate to see some love for SwiftUI users or at least a clarification if you have plans to get this working with SwiftUI as well. If not, the community could come up with their own wrapper library.

Thank you for sharing this and sorry for asking this question so early after its release. I'm not trying to say "please add SwiftUI support ASAP", I just want to know how you see that topic so I can better decide what to do if I need a feature like this in one of my SwiftUI apps.

How do I add custom images

I was adding image attachments with NSTextAttachment in my custom textView.(Like below)
let textAttachment = NSTextAttachment() textAttachment.bounds = CGRect(x: 0, y: (textView.font!.capHeight - image.size.height).rounded() / 2, width: image.size.width, height: image.size.height) textAttachment.image = image let attrStringWithImage = NSAttributedString(attachment: textAttachment) textView.textStorage.replaceCharacters(in: currentRange, with: attrStringWithImage)
Is there a way to add images(don't care if is it an NSTextAttachment or a suffixedAttachment) on the textView with TwitterTextEditor?

I found I can get hashtags with regex and place an UIImage or UIView after that hashtag. But I can't find a way how to add just UIImage itself like an NSTextAttachment.

Access UITextViewDelegate method shouldInteractWithURL

I'm looking to interact with UITextViewDelegate method func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool. Specifically say there's highlighted text such as a mention or a hashtag as part of the attributed string. If the user taps that text we'd want to route them to a page with the associated information.

Is this possible? Or am I missing an alternative way to implement this behavior?

And awesome job with this framework! Love the simplicity and safety of the API's it's been fun to try it out over the last couple weeks : )

One line summary of the issue

Describe the details of the issue.

Steps to reproduce the behavior

  • List all relevant brrnfnfnfbf fbfbfbfbdndndnfnfnfjfjffnfmsteps to reproduce the observed behavior.

Expected behavior

As concisely as possible, describe the expected behavior.

Actual behavior
Dhrhrhrhrhhr
As concisely as possible, describe the observed behavior.

Environment

  • Operating system name, version, and build number, such as “iOS 14.0.1 (18A393)”.
  • Hardware name and revision, such as “iPhone 11 Pro”.
  • Xcode version and build number, such as “12.0 (12A7209)”.
  • Any other dependencies, such as third-party keyboard and its version, if it’s applicable.

UIScrollViewDelegates not called as expected

Only certain start/end delegate methods of UIScrollViewDelegate are called.

Digging into the code it seems like these should be getting triggered. It's possible I'm not setting this up right but it's confusing as I'm definitely getting a couple of the delegates firing (see details below). I've set a breakpoint on line 88 of TextViewDelegateForwarder and only the below selectors are fired.

Steps to reproduce the behavior

  1. Conform a view controller that has TextEditorView as a subView to UIScrollViewDelegate.
  2. Implement UIScrollViewDelegate methods scrollViewWillBeginDragging, scrollViewDidEndDecelerating and scrollViewDidScroll.
  3. Assign TextEditorView's textView delegate to the conforming View Controller e.g. textEditorView.scrollView.delegate = self
  4. Test app and note that scrollViewWillBeginDragging and scrollViewDidEndDecelerating fire, but scrollViewDidScroll does not.

Expected behavior

When assigning the scroll view delegate, all UIScrollViewDelegate methods are called.

Actual behavior

Only scrollViewWillBeginDragging and scrollViewDidEndDecelerating fire.

Environment

  • iOS 14.5, 14.6
  • iPhone 11 Pro simulator (but also on others)
  • Xcode v12.5
  • TwitterTextEditor v 1.1.0

What's your take on making this library platform-independent?

Hello Twitter folks,
What's your take on making this library platform-independent?
Specifically, it now relies on UIKit which prevents it from being used on macOS.

Is supporting macOS on the radar? Both UITextView and NSTextView relies on the same NSTextStorage and NSTextContainer classes so I think this should be possible without a major refactor.
Would you accept a contribution that tries to make the library work on macOS?

Cheers 👋

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.