Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
714f293b
Commit
714f293b
authored
Jul 19, 2018
by
Orkhan Alikhanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed TextView font issue with emojis
parent
ef5db3d9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
Sources/iOS/TextView.swift
+39
-0
No files found.
Sources/iOS/TextView.swift
View file @
714f293b
...
...
@@ -107,10 +107,14 @@ open class TextView: UITextView {
}
}
/// Holds default font.
private
var
_font
:
UIFont
?
/// The placeholderLabel font value.
@IBInspectable
open
override
var
font
:
UIFont
?
{
didSet
{
_font
=
font
placeholderLabel
.
font
=
font
}
}
...
...
@@ -276,6 +280,18 @@ open class TextView: UITextView {
prepareRegularExpression
()
preparePlaceholderLabel
()
}
open
override
func
insertText
(
_
text
:
String
)
{
fixTypingFont
()
super
.
insertText
(
text
)
fixTypingFont
()
}
open
override
func
paste
(
_
sender
:
Any
?)
{
fixTypingFont
()
super
.
paste
(
sender
)
fixTypingFont
()
}
}
fileprivate
extension
TextView
{
...
...
@@ -442,3 +458,26 @@ extension TextView: TextStorageDelegate {
(
delegate
as?
TextViewDelegate
)?
.
textView
?(
textView
:
self
,
didProcessEditing
:
textStorage
,
text
:
string
,
range
:
range
)
}
}
private
extension
TextView
{
/// issue-838 and pr-1117
///
/// Inserting (typing or pasting) an emoji character or placing cursor after some
/// emoji characters (e.g ☺️) was causing typing font to change to "AppleColorEmoji"
/// and which was eventually falling back to "Courier New" when a non-emoji
/// character is inserted. This only happens only if `NSTextStorage` subclass is
/// used, otherwise typing font never changed to "AppleColorEmoji". So, we fix it
/// by resetting typing font from AppleColorEmoji to the default font set by the
/// developer. The fix is applied before and after inserting text. The former fixes
/// typing font change due to cursor placed after an emoji character, and the
/// latter fixes the typing font change due to the insertion of an emoji character
/// (typing font changes somehow are reflected in `UITextView.font` parameter).
func
fixTypingFont
()
{
let
fontAttribute
=
NSAttributedStringKey
.
font
.
rawValue
guard
(
typingAttributes
[
fontAttribute
]
as?
UIFont
)?
.
fontName
==
"AppleColorEmoji"
else
{
return
}
typingAttributes
[
fontAttribute
]
=
_font
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment