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

Support new UIManager API #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions src/NativeSafeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@ const first = (array, fn) => {
return null;
};

const getViewManagerConfig = (moduleName) => {
if (UIManager.getViewManagerConfig) {
// RN >= 0.58
return UIManager.getViewManagerConfig(moduleName)
}

// RN < 0.58
return UIManager[moduleName];
};

const moduleWithName = (nameOrArray) => {
if (!nameOrArray) return null;
if (Array.isArray(nameOrArray)) return first(nameOrArray, moduleWithName);
return UIManager[nameOrArray];
return getViewManagerConfig(nameOrArray);
};

const findFirstResolver = namespace => function findFirstOnNamespace(nameOrArray) {
Expand Down Expand Up @@ -74,7 +84,7 @@ function SafeComponentCreate(options) {
const PRIMARY_VIEW_NAME = getPrimaryName(viewName);

const realViewName = findFirstViewName(viewName);
const realViewConfig = UIManager[realViewName];
const realViewConfig = getViewManagerConfig(realViewName);

if (!realViewName || !realViewConfig) {
return mockComponent;
Expand Down Expand Up @@ -110,7 +120,7 @@ function SafeComponentCreate(options) {
return Platform.select({
android: () => UIManager.dispatchViewManagerCommand(
findNodeHandle(instance),
UIManager[realViewName].Commands[name],
getViewManagerConfig(realViewName).Commands[name],
args
),
ios: () => nativeModule[name](findNodeHandle(instance), ...args),
Expand Down