diff --git a/packages/layout/src/steps/resolveYoga.js b/packages/layout/src/steps/resolveYoga.js index e0c648af3..245fd81a0 100644 --- a/packages/layout/src/steps/resolveYoga.js +++ b/packages/layout/src/steps/resolveYoga.js @@ -1,7 +1,7 @@ import { loadYoga } from '../yoga/index'; -const resolveYoga = (root) => { - const yoga = loadYoga(); +const resolveYoga = async (root) => { + const yoga = await loadYoga(); return Object.assign({}, root, { yoga }); }; diff --git a/packages/layout/src/yoga/index.js b/packages/layout/src/yoga/index.js index 9c310dfd4..c00fd7a21 100644 --- a/packages/layout/src/yoga/index.js +++ b/packages/layout/src/yoga/index.js @@ -1,13 +1,14 @@ /* eslint-disable import/prefer-default-export */ -import Yoga from 'yoga-layout'; +import { loadYoga as yogaLoadYoga } from 'yoga-layout/load'; -export const loadYoga = () => { - const config = Yoga.Config.create(); +export const loadYoga = async () => { + const instance = await yogaLoadYoga(); + const config = instance.Config.create(); config.setPointScaleFactor(0); - const node = { create: () => Yoga.Node.createWithConfig(config) }; + const node = { create: () => instance.Node.createWithConfig(config) }; return { node }; }; diff --git a/packages/layout/tests/steps/resolvePagination.test.js b/packages/layout/tests/steps/resolvePagination.test.js index bcb3bd202..f84ba7215 100644 --- a/packages/layout/tests/steps/resolvePagination.test.js +++ b/packages/layout/tests/steps/resolvePagination.test.js @@ -10,7 +10,7 @@ const calcLayout = (node) => resolvePagination(resolveDimensions(node)); describe('pagination step', () => { test('should stretch absolute block to full page size', async () => { - const yoga = loadYoga(); + const yoga = await loadYoga(); const root = { type: 'DOCUMENT', @@ -63,7 +63,7 @@ describe('pagination step', () => { }); test('should force new height for split nodes', async () => { - const yoga = loadYoga(); + const yoga = await loadYoga(); const root = { type: 'DOCUMENT', @@ -113,7 +113,7 @@ describe('pagination step', () => { }); test('should force new height for split nodes with fixed height', async () => { - const yoga = loadYoga(); + const yoga = await loadYoga(); const root = { type: 'DOCUMENT', @@ -152,7 +152,7 @@ describe('pagination step', () => { }); test('should not wrap page with false wrap prop', async () => { - const yoga = loadYoga(); + const yoga = await loadYoga(); const root = { type: 'DOCUMENT', @@ -187,7 +187,7 @@ describe('pagination step', () => { }); test('should break on a container whose children can not fit on a page', async () => { - const yoga = loadYoga(); + const yoga = await loadYoga(); const root = { type: 'DOCUMENT', diff --git a/packages/layout/tests/steps/resolveTextLayout.test.js b/packages/layout/tests/steps/resolveTextLayout.test.js index c0fe97ee3..2cd567c7f 100644 --- a/packages/layout/tests/steps/resolveTextLayout.test.js +++ b/packages/layout/tests/steps/resolveTextLayout.test.js @@ -5,9 +5,9 @@ import { loadYoga } from '../../src/yoga'; import resolveTextLayout from '../../src/steps/resolveTextLayout'; import resolveDimensions from '../../src/steps/resolveDimensions'; -const getRoot = (text = 'hello world', styles = {}) => ({ +const getRoot = async (text = 'hello world', styles = {}) => ({ type: 'DOCUMENT', - yoga: loadYoga(), + yoga: await loadYoga(), children: [ { type: 'PAGE', @@ -38,14 +38,14 @@ describe('text layout step', () => { const getText = (root) => root.children[0].children[0]; test('should calculate lines for text while resolve dimensions', async () => { - const root = getRoot('text text text'); + const root = await getRoot('text text text'); const dimensions = resolveDimensions(root); expect(getText(dimensions).lines).toBeDefined(); }); test('should calculate lines for text width defined height', async () => { - const root = getRoot('text text text', { height: 50 }); + const root = await getRoot('text text text', { height: 50 }); const dimensions = resolveDimensions(root); expect(getText(dimensions).lines).not.toBeDefined(); @@ -56,7 +56,7 @@ describe('text layout step', () => { }); test('should calculate lines for empty text', async () => { - const root = getRoot(''); + const root = await getRoot(''); const dimensions = resolveDimensions(root); expect(getText(dimensions).lines).toBeDefined();