术语和标题 使用 Web 视图和按钮滚动



我想实现一个具有WebView(html文本(和按钮"我同意"和"取消"的内容页面

问题:我希望将 webView 插入到堆栈中,因此,我必须声明宽度和高度。 高度是我的主要问题,因为我想跨越或填充和扩展WebView。

所以我追求webView.Eval("一些js代码"(函数,但我无法获得返回值(html的高度? 此外,我从不同的方式接近,获取 web View onBottom 时的事件,然后获取一些布尔值。

这是代码:

StackLayout mainStackLayout = new StackLayout { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
Frame f = new Frame { BackgroundColor = Constants.iBackgroundWhite };
StackLayout motherStack = new StackLayout { Margin = new Thickness(15, 30) };
StackLayout buttonStack = new StackLayout
{
Orientation = StackOrientation.Horizontal,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Margin = new Thickness(0, 10)
};
Label captionLabel = new Label
{
Text = "Terms and Conditions",
TextColor = Constants.iPink,
FontAttributes = FontAttributes.Bold,
FontSize = 25,
Margin = new Thickness(10, 0, 0, 15)
};

var body = new HtmlWebViewSource();
body.Html = @"<html><body>
Lorem ipsum dolor sit amet, utinam tritani interpretaris mel ei, perfecto 
instructior ut vim. Usu ad erant maiorum, tollit latine ei ius, ea eos 
vitae nominati iracundia. Consul laboramus eam ad, eu est nisl expetendis 
philosophia. Doctus ceteros eu per, ut vel fierent similique accommodare, 
ius similique consectetuer et.
Te nec vero quas utamur, in possim nonumes inimicus his, an animal recusabo 
per. Eos ut natum bonorum legimus. Nihil liberavisse no usu. Sea dignissim 
mnesarchum cu, et per simul persius, constituto definitionem per in. No vix 
novum verear apeirian, aliquam accumsan definitionem mel at. Mea et autem 
phaedrum iracundia, reque vidisse at usu.
Ad mea commodo oportere. Quo ad debitis accusata atomorum. His dicit 
labores et, in dicat dolorum abhorreant est, ex qui voluptua oportere. Eum 
ex nonumy cotidieque signiferumque. Laudem commodo omittantur quo in, voluptua 
reformidans nam ad, ignota dicunt sed an. Mei ad sonet nonumes, no sit detracto 
officiis.
Cibo exerci duo eu. Has habeo atomorum disputationi te, ne has idque delicata. 
Cibo nihil euismod qui ut. Dicit ubique maiorum duo et, eam ad probo percipit 
sententiae. Quas lucilius vis ne. Id nec fabellas consetetur, sit id melius 
impetus cotidieque, eum fierent praesent rationibus id. Qui et liber offendit 
verterem, ad eripuit eruditi qui.
Vis affert instructior cu, cum id principes adolescens. Per omnes nominati 
salutatus at, ne audiam noluisse mel, aeque docendi fierent pro ne. At putant 
voluptua vis, duo ne etiam tritani. Ut solet laudem qualisque usu, dicunt 
adipisci his cu. Ea labore convenire corrumpit nec. Ne est quando virtute, 
virtute adipiscing an ius, an mei iracundia posidonium
</body> </html>";
_webView = new WebView
{
Source = body,
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
WidthRequest = App.ScreenWidth * 0.8,
HeightRequest = 500
};

_webView.IsEnabled = false;

#region Buttons
Button okButton = new Button();
okButton.SetWhiteButton();
okButton.Text = "I ACCEPT";
okButton.FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)) - 5;
okButton.WidthRequest = Device.GetNamedSize(NamedSize.Large, typeof(Button)) * 5;
okButton.BorderRadius = Constants.BorderRadius + 5;
Button cancelButton = new Button();
cancelButton.SetDefaultButton();
cancelButton.Text = "CANCEL";
cancelButton.FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)) - 5;
cancelButton.WidthRequest = Device.GetNamedSize(NamedSize.Large, typeof(Button)) * 5;
cancelButton.BorderRadius = Constants.BorderRadius + 5;
bool isChekedTaC = false;
okButton.Clicked += (s, e) =>
{
isChekedTaC = true;
Navigation.PushAsync(new RegisterOnePageNew(isChekedTaC, registrationRequestModel, "1234"));
};
#endregion
//var a = _webView.Eval("window.onscroll = function(ev) { if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight){alert('youre on the bottom');}};"
//_webView.Navigated += (o, s) => {
//    _webView.Eval("alert('text')");
//};
buttonStack.Children.Add(cancelButton);
buttonStack.Children.Add(okButton);
buttonStack.HorizontalOptions = LayoutOptions.CenterAndExpand;
buttonStack.VerticalOptions = LayoutOptions.Start;
grid.Children.Add(_webView, 0, 0);
//grid.Children.Add(buttonStack, 1, 0);

StackLayout sl = new StackLayout();
//sl.Children.Add(contentLabel);
sl.Children.Add(_webView);
sl.Children.Add(buttonStack);
mainStackLayout.Children.Add(captionLabel);
mainStackLayout.Children.Add(new ScrollView { Content = sl });
//mainStackLayout.Children.Add(buttonStack);
f.Content = mainStackLayout;
motherStack.Children.Add(f);
Content = sl;
}

protected override bool OnBackButtonPressed()
{
Navigation.PopAsync();
return true;
}

我只想在HTML WebView到达底部时显示我的两个按钮。我该怎么做?

#Option 1:在底部时返回真/假我设法用XLabs HybridWebView正确处理了一半。这是代码,也许对某人会很有用。

public class HybridView : ContentPage
{
HybridWebView hybrid;
public HybridView()
{
var stack = new StackLayout
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
BackgroundColor = Color.White
};
var body = new HtmlWebViewSource();
body.Html = @"<html><body>
Lorem ipsum dolor sit amet, utinam tritani interpretaris mel ei, perfecto instructior ut vim. Usu ad erant maiorum, tollit latine ei ius, ea eos vitae nominati iracundia. Consul laboramus eam ad, eu est nisl expetendis philosophia. Doctus ceteros eu per, ut vel fierent similique accommodare, ius similique consectetuer et.
Te nec vero quas utamur, in possim nonumes inimicus his, an animal recusabo per. Eos ut natum bonorum legimus. Nihil liberavisse no usu. Sea dignissim mnesarchum cu, et per simul persius, constituto definitionem per in. No vix novum verear apeirian, aliquam accumsan definitionem mel at. Mea et autem phaedrum iracundia, reque vidisse at usu.
Ad mea commodo oportere. Quo ad debitis accusata atomorum. His dicit labores et, in dicat dolorum abhorreant est, ex qui voluptua oportere. Eum ex nonumy cotidieque signiferumque. Laudem commodo omittantur quo in, voluptua reformidans nam ad, ignota dicunt sed an. Mei ad sonet nonumes, no sit detracto officiis.
Cibo exerci duo eu. Has habeo atomorum disputationi te, ne has idque delicata. Cibo nihil euismod qui ut. Dicit ubique maiorum duo et, eam ad probo percipit sententiae. Quas lucilius vis ne. Id nec fabellas consetetur, sit id melius impetus cotidieque, eum fierent praesent rationibus id. Qui et liber offendit verterem, ad eripuit eruditi qui.
Vis affert instructior cu, cum id principes adolescens. Per omnes nominati salutatus at, ne audiam noluisse mel, aeque docendi fierent pro ne. At putant voluptua vis, duo ne etiam tritani. Ut solet laudem qualisque usu, dicunt adipisci his cu. Ea labore convenire corrumpit nec. Ne est quando virtute, virtute adipiscing an ius, an mei iracundia posidonium.
</body> </html>";

hybrid = new HybridWebView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
BackgroundColor = Color.White,
WidthRequest = 300,
HeightRequest = 600,
Source = body
};
stack.Children.Add(hybrid);
Content = stack;
}
protected override void OnAppearing()
{
base.OnAppearing();
hybrid.InjectJavaScript("window.onscroll = function(ev) { if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight){alert('youre on the bottom');}};");
}
}

现在我必须弄清楚如何从js获取xamarin表单的信息

您可以将"我同意"和"取消"按钮放入 HTML 中,然后注入到您的旧源代码中。这样,您可以使用单个 Web 视图来显示所有内容。

相关内容

  • 没有找到相关文章

最新更新