Skip to content
This repository was archived by the owner on Aug 12, 2022. It is now read-only.

Conversation

@chrisgarrity
Copy link
Contributor

Resolves

Preparation for #274

Proposed Changes

Refactor the native interface in preparation for switching iOS to use WKWebview.

  • Finally rename the folder for device specific interfaces as tablet instead of iPad
  • Update import statements to use the new name
  • Create new iOS.js and Android.js based on previous iPad/iOS.js to separate the interfaces
  • Add new OS constant to utils/lib that records the current platform based on navigtor.userAgent based on https://stackoverflow.com/questions/37591279/detect-if-user-is-using-webview-for-android-ios-or-a-regular-browser
    It can be difficult to detect the difference between in a browser and in a webview, but for now ScratchJr doesn’t need to worry about running in a browser

Reason for Changes

Having all the device dependent files named iPad and iOS even when they applied to Android has been a source of confusion for a very long time. The way that iOS WKWebview and Android webview handle communications between javascript and the native side is quite different. Having them be two completely separate interfaces allows us to handle them differently as needed - for example, deciding when things need to be JSON.stringified and when the interface will take care of it.

Test Coverage

Manual testing:

  • iOS: tested on simulator (so no camera) I'll recheck on a real device once I have charged an iPad.
    • able to create projects, add pages, add sprite, add background, add sounds, add text
    • was not able to export project on simulator (bug or simulator limitation?)
  • Android: tested on Android 5.0.2 (Samsung tablet)
    *able to create projects, add pages, add sprites, add backgrounds, add sound, add text, use camera in paint editor, export via email

}
// // XXX: does this ever happen?
// // I'm pretty sure this is dead code -TM
// static saveProjectState () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was sure enough that it's dead code to just comment it out. Probably should just remove it completely.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I can't find anything that points to it, I say go for it and delete!

@chrisgarrity chrisgarrity marked this pull request as draft August 7, 2020 19:23
Refactor the native interface in preparation for switching iOS to use WKWebview.
* Finally rename the folder for device specific interfaces as `tablet` instead of `iPad`
* Update `import` statements to use the new name
* Create new `iOS.js` and `Android.js` based on previous `iPad/iOS.js` to separate the interfaces
* Add new `OS.js` class to manage the class variables, initialize the device interface delegate methods to the correct interface.
* refactor how  `utils/lib` detects the current platform based on `navigtor.userAgent` based on https://stackoverflow.com/questions/37591279/detect-if-user-is-using-webview-for-android-ios-or-a-regular-browser. previous method relied on the Android interface being loaded or not. It can be difficult to detect the difference between in a browser and in a webview, but for now ScratchJr doesn’t need to worry about running in a browser
@chrisgarrity chrisgarrity force-pushed the issue/274-refactor-os-interface branch from 0827c6b to 1420a59 Compare August 10, 2020 13:12
}
var me = this;
var url = (MediaLib.keys[name]) ? MediaLib.path + name : (name.indexOf('/') < 0) ? iOS.path + name : name;
var url = (MediaLib.keys[name]) ?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was just fixing a lint error

@chrisgarrity chrisgarrity marked this pull request as ready for review August 10, 2020 13:16
Android Studio added some more config files.
@chrisgarrity chrisgarrity mentioned this pull request Aug 10, 2020
8 tasks
src/tablet/OS.js Outdated
tabletInterface.getmedia(file, fcn);
}

// static getmediadata (key, offset, len, fcn) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar comment to the one I left above: could you add a note about when it would be appropriate to delete this code, so it doesn't stay in limbo forever?


// // Called on the Objective-C side. The argument is a base64-encoded .SJR file,
// // to be unzipped, processed, and stored.
// static loadProjectFromSjr (b64data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see note above


export default class iOS {

// waitForInterface is defined in OS, and should make sure that the correct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see note above


// // Web Wiew delegate call backs
//
// static pageError (desc) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see note above

// safari = /safari/.test( userAgent ), // currently do not need to detect browser vs webview
// android = /android/.text.(userAgent);

if( ios ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be more consistent with our style:

Suggested change
if( ios ) {
if (ios) {

@benjiwheeler
Copy link
Contributor

LGTM, with a few suggestions that are minor!

removing dead code that was just commented in the previous commit,
@chrisgarrity chrisgarrity merged commit d6e1a77 into develop Aug 10, 2020
@chrisgarrity chrisgarrity deleted the issue/274-refactor-os-interface branch August 10, 2020 20:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants