Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Scott's expanded safari webview
Started by davida6 Mar 04 2018 01:20 PM

22 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

davida6

[GLOBAL: userInfoPane.html]
davida6
  • Contributor

  • 129 posts
  • Corona SDK

Hi, Scott.

 

Does your plugin allow a youtube video to run within an iframe, or does it expand to full screen like the Corona implementation in the Xcode simulator?

 

Thanks

 

Dave

 



[TOPIC: post.html]
#2

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,810 posts
  • Enterprise

It plays in full screen



[TOPIC: post.html]
#3

davida6

[GLOBAL: userInfoPane.html]
davida6
  • Contributor

  • 129 posts
  • Corona SDK

Darn, but thanks.

D

[TOPIC: post.html]
#4

davida6

[GLOBAL: userInfoPane.html]
davida6
  • Contributor

  • 129 posts
  • Corona SDK

Hi, Scott.

 

I'm working with the safariWebView and have a couple of questions:

 

1.  The native.newWebVIew, for a local file, takes 2 parameters - the url and a baseDir (in my case system.DocumentsDIrectory)

             Your answer to this is the requestFromFile(path) - which would go as requestFromFile(system.pathFromFile(url,baseDir)): correct?

 

2.  Shouldnt errors in the loading/display (like file not found) pass through the listener,  setup in the view initialization?

 

I see status messages in the log, but nothing coming through the listener, and nothing happening on the screen.

 

Thanks

 

Dave



[TOPIC: post.html]
#5

davida6

[GLOBAL: userInfoPane.html]
davida6
  • Contributor

  • 129 posts
  • Corona SDK

Hi, Scott - let's update the last message.

 

It looks like I was having some trouble with the javascript in the html file - and it wasnt getting the passed variable.  I got rid of the json call in the listener, since the data coming in was a table - switched to print_r - and was able to figure that part out.

 

I switched to the requestFromString(x), handled the passed variable myself, and passed the "page" into the request and everything worked as hoped and expected: the youtube video stayed where it was supposed to and played without any of the buffering/timeing issues I see under android.

 

Did the setup in my last post here look right for the requestFromFile - again, it may have been the javascript that mucked things up.

 

Thanks

 

Dave



[TOPIC: post.html]
#6

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,810 posts
  • Enterprise

Good to hear :)

[TOPIC: post.html]
#7

davida6

[GLOBAL: userInfoPane.html]
davida6
  • Contributor

  • 129 posts
  • Corona SDK

Scott,

 

Should I be able to insert the object into a dispay group?  and should there be a removeSelf() to kill the object?

 

Thanks

 

Dave



[TOPIC: post.html]
#8

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,810 posts
  • Enterprise

Unfortunately display groups are not supported, Corona has not provided any documentation on how to implement display groups with native objects.
There is a destroy api

[TOPIC: post.html]
#9

davida6

[GLOBAL: userInfoPane.html]
davida6
  • Contributor

  • 129 posts
  • Corona SDK

My apologies - totally missed the destroy.

thanks.

 

Dave



[TOPIC: post.html]
#10

a3mg

[GLOBAL: userInfoPane.html]
a3mg
  • Enthusiast

  • 50 posts
  • Corona SDK

I downloaded the sample "safariWebView-Demo-master" but I'm not able to get it to load a very simple "hello world" index.html local file. I have been trying

view:requestFromFile(system.pathForFile("index.html",system.ResourceDirectory))

But it never displays the local file.

 

Works fine if I use a web URL like this (and other "https" URLs).

view:request("https://www.coronalabs.com")

What am I doing wrong, any suggestions?

 

Corona 3184, iPad iOS 11.2



[TOPIC: post.html]
#11

davida6

[GLOBAL: userInfoPane.html]
davida6
  • Contributor

  • 129 posts
  • Corona SDK

I'm using the requestFromString() under iOS and the standard web view on Android - mainly because of issues with the url variable not being handled properly.  This code runs an embedded youtube video.

local url = "tutorials.html?ID=" .. goto
if (ios) then
     local xx = "<html><body><div style=\"text-align: center; align: center; background-color: black;\">"
     xx = xx .. "<iframe style=\'width: 100%; height: 100%;\' src=\"https://www.youtube.com/embed/" .. goto 
     xx = xx .. "?rel=0&amp;controls=0&amp;showinfo=0\" frameborder=\"1\" allowfullscreen></iframe></div></body></html>"
     wView:requestFromString(xx)
else
     wView:request(url, system.DocumentsDirectory)
end	

I found that Scott's request() and requestFrom String() ran clean, so I didn't pursue the requestFromFile().

 

Not exactly what you were looking for, but hope it helps.

 

Dave



[TOPIC: post.html]
#12

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,810 posts
  • Enterprise

I downloaded the sample "safariWebView-Demo-master" but I'm not able to get it to load a very simple "hello world" index.html local file. I have been trying

view:requestFromFile(system.pathForFile("index.html",system.ResourceDirectory))

But it never displays the local file.

 

Works fine if I use a web URL like this (and other "https" URLs).

view:request("https://www.coronalabs.com")

What am I doing wrong, any suggestions?

 

Corona 3184, iPad iOS 11.2

This has been patched please wait an hour



[TOPIC: post.html]
#13

a3mg

[GLOBAL: userInfoPane.html]
a3mg
  • Enthusiast

  • 50 posts
  • Corona SDK

Scott -

 

Thank you for providing the patch, loading a local html file is working as expected.

 

I have another question.  Is it possible to use the "lis(function)" of the safariWebView plugin in the same was as using the corona webView:addEventListener( "urlRequest", webListener ) to listen while using the html pages?

 

I used a native.showAlert to see the event.url when the safariWebView plugin loads the index.html page for the first time. Is there something similar I can use to listen for other events like event.url after the page loads?  With the corona webview I use html forms to call functions in corona.  Here is a simple example

function webViewListener( event )
	if (event.url == "corona:playVideo1?") then
		playVideo1()
	end
	
	if (event.url == "corona:openLink1?") then
		openLink1()
	end
end


[TOPIC: post.html]
#14

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,810 posts
  • Enterprise

Yes it does please see documentation
https://scotth.tech/plugin-safariWebview

[TOPIC: post.html]
#15

a3mg

[GLOBAL: userInfoPane.html]
a3mg
  • Enthusiast

  • 50 posts
  • Corona SDK

Scott -
 
I see how the listener is working in the Safari WebView Plugin.  It seems to only hear when the initial page is loaded in or when navigating to new pages.  
 
I have instances where other pages are loaded into a <div> or <iframe> on the page that is loaded in to the Safari WebView Plugin and it does not seem to "hear" when navigating those pages.  When I load a single index.html page that has the listener set to alert the events, I can see the event info when the page initially loads.  But I see nothing when pages load into <div> on the page or when navigating to different pages in those divs.  I only see another listener event if navigating from the index.html to another page at that top level.
 
The Corona native webview also listens for <form> submit which is actually how I use the listener.  It does not seem that Safari WebView Plugin listener reports any events for a form submit, even on the top level index.html page that I was testing.
 
Would it be possible to have the Safari WebView Plugin listener hear the events on all the pages that are loaded into plugin even if they are in a <div> or <iframe>?
 
Is it possible for the Safari WebView Plugin to listen for a <form> submit?


[TOPIC: post.html]
#16

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,810 posts
  • Enterprise

Could you not try to add the data to the url via ?data=mydata

[TOPIC: post.html]
#17

a3mg

[GLOBAL: userInfoPane.html]
a3mg
  • Enthusiast

  • 50 posts
  • Corona SDK

Is there a maximum height or width for the webview?  I am trying to code for iPhone X, Xs, Xr, and Xs Max and no matter what I do I can't get the webview to get any bigger.  Even if I use obviously too large height and width for the webview.



[TOPIC: post.html]
#18

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,810 posts
  • Enterprise

Have you tried on physical devices?



[TOPIC: post.html]
#19

redpistonCrna

[GLOBAL: userInfoPane.html]
redpistonCrna
  • Observer

  • 9 posts
  • Corona SDK

Scott, is there any way to hide the webview until it has fired the "finished" event?

 

With Corona's Native webview, I was showing a loading spinner in Corona rotating, and once the "loaded" event was fired I would set isVisible = true to the webview.

 

It seems like your webview doesn't have this functionality. I also tried to load it off screen (x=-1000) and then on "finished" set it to x=display.contentCenterX, but changing the x or y positions seem to do nothing. Also tried having the width as 0 and then setting it once loaded to full width, but again no change occurred.

 

Please help! Are the position and size properties only allowed to be set on init? Can this be fixed?



[TOPIC: post.html]
#20

redpistonCrna

[GLOBAL: userInfoPane.html]
redpistonCrna
  • Observer

  • 9 posts
  • Corona SDK

Scott, is there any way to hide the webview until it has fired the "finished" event?

 

With Corona's Native webview, I was showing a loading spinner in Corona rotating, and once the "loaded" event was fired I would set isVisible = true to the webview.

 

It seems like your webview doesn't have this functionality. I also tried to load it off screen (x=-1000) and then on "finished" set it to x=display.contentCenterX, but changing the x or y positions seem to do nothing. Also tried having the width as 0 and then setting it once loaded to full width, but again no change occurred.

 

Please help! Are the position and size properties only allowed to be set on init? Can this be fixed?

 

 

Ahhh nvm, it was just a bug/scope issue in my code. For anyone else reading this; changing the x and y properties DOES work.

 

Awesome job Scott, thanks for your hard work.



[TOPIC: post.html]
#21

redpistonCrna

[GLOBAL: userInfoPane.html]
redpistonCrna
  • Observer

  • 9 posts
  • Corona SDK

Would you be able to add this functionality?

 

webView.hasBackground = false



[TOPIC: post.html]
#22

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,810 posts
  • Enterprise

^ let me check



[TOPIC: post.html]
#23

Scott Harrison

[GLOBAL: userInfoPane.html]
Scott Harrison
  • Corona Geek

  • 1,810 posts
  • Enterprise

Would you be able to add this functionality?

 

webView.hasBackground = false

No, it does not appear there is a good way to implement in the webkit api

I don't know what you were planning but you may you try hiding it off screen.




[topic_controls]
[/topic_controls]