Last active
June 21, 2018 12:07
-
-
Save agenthunt/1cc881a6d2b04cb09aaffe727e6cb2af to your computer and use it in GitHub Desktop.
hello-react-native-custom-renderer-myReactNativeWebRenderer-createInstance.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
createInstance: (type, newProps, rootContainerInstance, _currentHostContext, workInProgress) => { | |
const domElement = document.createElement('div'); | |
Object.keys(newProps).forEach(propName => { | |
const propValue = newProps[propName]; | |
if (propName === 'children') { | |
if (type !== 'text') { | |
if (typeof propValue === 'string' || typeof propValue === 'number') { | |
throw new Error('Text strings must be rendered within a <Text> component.'); | |
} | |
if (propValue instanceof Array) { | |
propValue.forEach(item => { | |
if (typeof item === 'string') { | |
throw new Error('Text strings must be rendered within a <Text> component.'); | |
} | |
}); | |
} | |
} | |
} else if (propName === 'style') { | |
const styleString = convertCamelCasetoInlineStyle(propValue); | |
domElement.setAttribute('style', styleString); | |
} else { | |
const propValue = newProps[propName]; | |
domElement.setAttribute(propName, propValue); | |
} | |
}); | |
return domElement; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment