Skip to content

Commit

Permalink
Fix: parent node touch, SafeAreaView wrapper android
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyhuman committed Nov 7, 2022
1 parent f40715c commit 129e413
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
9 changes: 8 additions & 1 deletion example/components/DomCounter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Platform } from 'react-native'

export default function DomApp() {
let count = 0
let saView
if (Platform.OS === 'android') {
saView = document.createElement('View')
} else {
saView = document.createElement('SafeAreaView')
}

const saView = document.createElement('SafeAreaView')
const view = document.createElement('View')
const text = document.createElement('Text')
text.textContent = count
Expand Down
7 changes: 6 additions & 1 deletion src/components.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Platform } from 'react-native'
import { h } from 'preact'

export function SafeAreaView({ ...props }) {
return h('SafeAreaView', props)
let compName = 'SafeAreaView'
if (Platform.OS === 'android') {
compName = 'View'
}
return h(compName, props)
}

export function View({ ...props }) {
Expand Down
18 changes: 12 additions & 6 deletions src/dom/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class Bridge {
if (Object.keys(FALSE_TYPES).indexOf(type) > -1) {
break
}
const rawViewClass = TYPES[type]

const rawViewClass = TYPES[type]
if (type === '#text') {
ReactNativePrivateInterface.UIManager.createView(
binding.id,
Expand Down Expand Up @@ -153,8 +153,6 @@ class Bridge {
parentTag = ROOT_TAG
}

// if conflicting indices between create and move,
// add the child at a later index and then to the remaining
ReactNativePrivateInterface.UIManager.manageChildren(
parentTag, // containerID
moveFrom, // moveFromIndices
Expand All @@ -167,6 +165,7 @@ class Bridge {
break
}
case 'event': {
const targetId = params[0]
this.handleEvent('event', params)
break
}
Expand Down Expand Up @@ -363,6 +362,9 @@ function receiveTouches(eventTopLevelType, touches, changedIndices) {
return
}

if (nodeId === registry.root) {
return
}
executeTouchEvent.call(this, nodeId, eventTopLevelType, nativeEvent)
}

Expand All @@ -378,14 +380,18 @@ function executeKeyboardEvent(nodeId, eventTopLevelType, nativeEvent = {}) {
this.enqueue('event', [nodeId, eventTopLevelType, nativeEvent])
}

// TODO: if used somewhere else, add to
// a shared folder
const microTask = fn => setTimeout(fn, 1)

function process() {
const q = this.queue || []
let methodDef = q.shift()
if (methodDef) {
dispatch.call(this, methodDef)
// setTimeout(() => {
process.call(this)
// }, 1)
microTask(() => {
process.call(this)
})
} else {
this.processing = false
}
Expand Down

0 comments on commit 129e413

Please sign in to comment.