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
bf70e91f
Unverified
Commit
bf70e91f
authored
Mar 20, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: added handlers for keyboard changes in TextView
parent
52161cec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
4 deletions
+60
-4
Sources/iOS/TextField.swift
+3
-1
Sources/iOS/TextView.swift
+57
-3
No files found.
Sources/iOS/TextField.swift
View file @
bf70e91f
...
@@ -399,6 +399,8 @@ open class TextField: UITextField {
...
@@ -399,6 +399,8 @@ open class TextField: UITextField {
borderStyle
=
.
none
borderStyle
=
.
none
backgroundColor
=
nil
backgroundColor
=
nil
contentScaleFactor
=
Screen
.
scale
contentScaleFactor
=
Screen
.
scale
font
=
RobotoFont
.
regular
(
with
:
16
)
textColor
=
Color
.
darkText
.
primary
prepareDivider
()
prepareDivider
()
preparePlaceholderLabel
()
preparePlaceholderLabel
()
...
@@ -426,8 +428,8 @@ extension TextField {
...
@@ -426,8 +428,8 @@ extension TextField {
/// Prepares the placeholderLabel.
/// Prepares the placeholderLabel.
fileprivate
func
preparePlaceholderLabel
()
{
fileprivate
func
preparePlaceholderLabel
()
{
font
=
RobotoFont
.
regular
(
with
:
16
)
placeholderNormalColor
=
Color
.
darkText
.
others
placeholderNormalColor
=
Color
.
darkText
.
others
placeholderLabel
.
backgroundColor
=
.
clear
addSubview
(
placeholderLabel
)
addSubview
(
placeholderLabel
)
}
}
...
...
Sources/iOS/TextView.swift
View file @
bf70e91f
...
@@ -49,6 +49,22 @@ public protocol TextViewDelegate : UITextViewDelegate {
...
@@ -49,6 +49,22 @@ public protocol TextViewDelegate : UITextViewDelegate {
optional
func
textView
(
textView
:
TextView
,
willHideKeyboard
value
:
NSValue
)
optional
func
textView
(
textView
:
TextView
,
willHideKeyboard
value
:
NSValue
)
/**
/**
A delegation method that is executed when the keyboard did open.
- Parameter textView: A TextView.
- Parameter didShowKeyboard value: A NSValue.
*/
@objc
optional
func
textView
(
textView
:
TextView
,
didShowKeyboard
value
:
NSValue
)
/**
A delegation method that is executed when the keyboard did close.
- Parameter textView: A TextView.
- Parameter didHideKeyboard value: A NSValue.
*/
@objc
optional
func
textView
(
textView
:
TextView
,
didHideKeyboard
value
:
NSValue
)
/**
A delegation method that is executed when text will be
A delegation method that is executed when text will be
processed during editing.
processed during editing.
- Parameter textView: A TextView.
- Parameter textView: A TextView.
...
@@ -265,6 +281,8 @@ open class TextView: UITextView {
...
@@ -265,6 +281,8 @@ open class TextView: UITextView {
contentScaleFactor
=
Screen
.
scale
contentScaleFactor
=
Screen
.
scale
textContainerInset
=
.
zero
textContainerInset
=
.
zero
backgroundColor
=
nil
backgroundColor
=
nil
font
=
RobotoFont
.
regular
(
with
:
16
)
textColor
=
Color
.
darkText
.
primary
prepareNotificationHandlers
()
prepareNotificationHandlers
()
prepareRegularExpression
()
prepareRegularExpression
()
preparePlaceholderLabel
()
preparePlaceholderLabel
()
...
@@ -277,6 +295,8 @@ extension TextView {
...
@@ -277,6 +295,8 @@ extension TextView {
let
defaultCenter
=
NotificationCenter
.
default
let
defaultCenter
=
NotificationCenter
.
default
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleKeyboardWillShow(notification:)
)
,
name
:
NSNotification
.
Name
.
UIKeyboardWillShow
,
object
:
nil
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleKeyboardWillShow(notification:)
)
,
name
:
NSNotification
.
Name
.
UIKeyboardWillShow
,
object
:
nil
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleKeyboardWillHide(notification:)
)
,
name
:
NSNotification
.
Name
.
UIKeyboardWillHide
,
object
:
nil
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleKeyboardWillHide(notification:)
)
,
name
:
NSNotification
.
Name
.
UIKeyboardWillHide
,
object
:
nil
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleKeyboardDidShow(notification:)
)
,
name
:
NSNotification
.
Name
.
UIKeyboardDidShow
,
object
:
nil
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleKeyboardDidHide(notification:)
)
,
name
:
NSNotification
.
Name
.
UIKeyboardDidHide
,
object
:
nil
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleTextViewTextDidBegin
)
,
name
:
NSNotification
.
Name
.
UITextViewTextDidBeginEditing
,
object
:
self
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleTextViewTextDidBegin
)
,
name
:
NSNotification
.
Name
.
UITextViewTextDidBeginEditing
,
object
:
self
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleTextViewTextDidChange
)
,
name
:
NSNotification
.
Name
.
UITextViewTextDidChange
,
object
:
self
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleTextViewTextDidChange
)
,
name
:
NSNotification
.
Name
.
UITextViewTextDidChange
,
object
:
self
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleTextViewTextDidEnd
)
,
name
:
NSNotification
.
Name
.
UITextViewTextDidEndEditing
,
object
:
self
)
defaultCenter
.
addObserver
(
self
,
selector
:
#selector(
handleTextViewTextDidEnd
)
,
name
:
NSNotification
.
Name
.
UITextViewTextDidEndEditing
,
object
:
self
)
...
@@ -289,7 +309,7 @@ extension TextView {
...
@@ -289,7 +309,7 @@ extension TextView {
/// prepares the placeholderLabel property.
/// prepares the placeholderLabel property.
fileprivate
func
preparePlaceholderLabel
()
{
fileprivate
func
preparePlaceholderLabel
()
{
placeholderLabel
.
font
=
font
placeholderLabel
.
textColor
=
Color
.
darkText
.
others
placeholderLabel
.
textAlignment
=
textAlignment
placeholderLabel
.
textAlignment
=
textAlignment
placeholderLabel
.
numberOfLines
=
0
placeholderLabel
.
numberOfLines
=
0
placeholderLabel
.
backgroundColor
=
.
clear
placeholderLabel
.
backgroundColor
=
.
clear
...
@@ -336,13 +356,30 @@ extension TextView {
...
@@ -336,13 +356,30 @@ extension TextView {
return
return
}
}
guard
let
v
=
notification
.
userInfo
?[
UIKeyboardFrameBeginUserInfoKey
]
as?
NSValue
else
{
return
}
(
delegate
as?
TextViewDelegate
)?
.
textView
?(
textView
:
self
,
willShowKeyboard
:
v
)
}
/**
Handler for when the keyboard did open.
- Parameter notification: A Notification.
*/
@objc
fileprivate
func
handleKeyboardDidShow
(
notification
:
Notification
)
{
guard
isKeyboardHidden
else
{
return
}
isKeyboardHidden
=
false
isKeyboardHidden
=
false
guard
let
v
=
notification
.
userInfo
?[
UIKeyboardFrameBeginUserInfoKey
]
as?
NSValue
else
{
guard
let
v
=
notification
.
userInfo
?[
UIKeyboardFrameBeginUserInfoKey
]
as?
NSValue
else
{
return
return
}
}
(
delegate
as?
TextViewDelegate
)?
.
textView
?(
textView
:
self
,
will
ShowKeyboard
:
v
)
(
delegate
as?
TextViewDelegate
)?
.
textView
?(
textView
:
self
,
did
ShowKeyboard
:
v
)
}
}
/**
/**
...
@@ -355,13 +392,30 @@ extension TextView {
...
@@ -355,13 +392,30 @@ extension TextView {
return
return
}
}
guard
let
v
=
notification
.
userInfo
?[
UIKeyboardFrameEndUserInfoKey
]
as?
NSValue
else
{
return
}
(
delegate
as?
TextViewDelegate
)?
.
textView
?(
textView
:
self
,
willHideKeyboard
:
v
)
}
/**
Handler for when the keyboard did close.
- Parameter notification: A Notification.
*/
@objc
fileprivate
func
handleKeyboardDidHide
(
notification
:
Notification
)
{
guard
!
isKeyboardHidden
else
{
return
}
isKeyboardHidden
=
true
isKeyboardHidden
=
true
guard
let
v
=
notification
.
userInfo
?[
UIKeyboardFrameEndUserInfoKey
]
as?
NSValue
else
{
guard
let
v
=
notification
.
userInfo
?[
UIKeyboardFrameEndUserInfoKey
]
as?
NSValue
else
{
return
return
}
}
(
delegate
as?
TextViewDelegate
)?
.
textView
?(
textView
:
self
,
will
HideKeyboard
:
v
)
(
delegate
as?
TextViewDelegate
)?
.
textView
?(
textView
:
self
,
did
HideKeyboard
:
v
)
}
}
/// Notification handler for when text editing began.
/// Notification handler for when text editing began.
...
...
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