Skip to content
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

Fix android call next #3088

Closed
Closed
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
21 changes: 14 additions & 7 deletions packages/slate-react/src/plugins/android/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ function AndroidPlugin({ editor }) {
* handle `onCompositionStart`
*/

function onCompositionStart() {
function onCompositionStart(event, e, next) {
observer.onCompositionStart()
return next()
}

/**
* handle `onCompositionEnd`
*/

function onCompositionEnd() {
function onCompositionEnd(event, e, next) {
observer.onCompositionEnd()
return next()
}

/**
Expand All @@ -62,26 +64,29 @@ function AndroidPlugin({ editor }) {
* @param {Event} event
*/

function onSelect(event) {
function onSelect(event, e, next) {
const window = getWindow(event.target)
fixSelectionInZeroWidthBlock(window)
observer.onSelect(event)
return next()
}

/**
* handle `onComponentDidMount`
*/

function onComponentDidMount() {
function onComponentDidMount(event, e, next) {
observer.connect()
return next()
}

/**
* handle `onComponentDidUpdate`
*/

function onComponentDidUpdate() {
function onComponentDidUpdate(event, e, next) {
observer.connect()
return next()
}

/**
Expand All @@ -90,8 +95,9 @@ function AndroidPlugin({ editor }) {
* @param {Event} event
*/

function onComponentWillUnmount() {
function onComponentWillUnmount(event, e, next) {
observer.disconnect()
return next()
}

/**
Expand All @@ -100,12 +106,13 @@ function AndroidPlugin({ editor }) {
* @param {Event} event
*/

function onRender() {
function onRender(event, e, next) {
observer.disconnect()

// We don't want the `diff` from a previous render to apply to a
// potentially different value (e.g. when we switch examples)
observer.clearDiff()
return next()
}

return {
Expand Down
8 changes: 7 additions & 1 deletion packages/slate-react/src/plugins/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ function DOMPlugin(options = {}) {
const beforePlugin = BeforePlugin()
const afterPlugin = AfterPlugin()

// Activate NoopPlugin only for debugging purposes
const noopPluginActivated = false

// COMPAT: Add Android specific handling separately before it gets to the
// other plugins because it is specific (other browser don't need it) and
// finicky (it has to come before other plugins to work).
const androidPlugins = IS_ANDROID
? [AndroidPlugin(options), NoopPlugin(options)]
? [
AndroidPlugin(options),
noopPluginActivated ? NoopPlugin(options) : undefined,
]
: []

return [...androidPlugins, beforePlugin, ...plugins, afterPlugin]
Expand Down