Skip to content

Commit

Permalink
Merge pull request #1 from lh0x00/bugfix/SupportNewestReactVersion
Browse files Browse the repository at this point in the history
Support React 18
  • Loading branch information
iBinh authored Dec 29, 2022
2 parents 229e707 + f333402 commit 03ab7a0
Show file tree
Hide file tree
Showing 3 changed files with 4,015 additions and 3,467 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@
"jsdom": "^15.0.0",
"ocular-dev-tools": "^0.2.2",
"pre-commit": "^1.2.2",
"react": "^16.3.0",
"react-dom": "^16.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer": "^16.3.0",
"reify": "^0.18.1",
"sinon": "4.1.3",
"typescript": "^4.0.0"
},
"peerDependencies": {
"react": ">=16.3.0"
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"pre-commit": [
"test-fast"
Expand Down
12 changes: 8 additions & 4 deletions src/goong/goong.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,17 @@ export default class Goong {
this._map = Goong.savedMap;
// When reusing the saved map, we need to reparent the map(canvas) and other child nodes
// intoto the new container from the props.
// Step1: reparenting child nodes from old container to new container
// Step1: reparenting child nodes from old container to new container, do not execute if same element, otherwise will loop and crash.
const oldContainer = this._map.getContainer();
const newContainer = props.container;
newContainer.classList.add('mapboxgl-map');
while (oldContainer.childNodes.length > 0) {
newContainer.appendChild(oldContainer.childNodes[0]);

if (oldContainer !== newContainer) {
while (oldContainer.childNodes.length > 0) {
newContainer.appendChild(oldContainer.childNodes[0]);
}
}

// Step2: replace the internal container with new container from the react component
this._map._container = newContainer;
Goong.savedMap = null;
Expand Down Expand Up @@ -285,7 +289,7 @@ export default class Goong {
return;
}

if (!Goong.savedMap) {
if (this.props.reuseMaps && !Goong.savedMap) {
Goong.savedMap = this._map;

// deregister the goong event listeners
Expand Down
Loading

0 comments on commit 03ab7a0

Please # to comment.