Git Product home page Git Product logo

Comments (5)

TimLariviere avatar TimLariviere commented on May 27, 2024 1

Hi Ben,

Fabulous works on top of Xamarin.Forms, so it could theoretically run anywhere XF is supported.
After looking at the documentation for XF/Share extensions, it seems to use the integration of Xamarin.Forms into a native view, aka "Native Forms".

Today, Fabulous doesn't support it as the program loop is tied to a Xamarin.Forms.Application instance which a share extension wouldn't have. That said, I have already validated that we can make Fabulous work against any XF control instead of just a Xamarin.Forms.Application. (see fabulous-dev/Fabulous#738 (comment))

Didn't had time to integrate that new feature for now, but if you want, you can make your own Fabulous Host with a couple lines of code to see if you can write your share extension with Fabulous.

We would gladly accept a PR if that's the case.

For the modification, see this code:
https://github.com/fsprojects/Fabulous/blob/dda14abbf1d906de2fe576a4e7940bc94eb4df8c/Fabulous.XamarinForms/src/Fabulous.XamarinForms.Core/Program.fs#L8-L18

Fabulous will consume the IHost interface, so you can implement a XamarinFormsContentPageHost that takes a ContentPage instead of an Application.
The GetRootView and SetRootView methods would get/set the Content property.

Then you can write a few functions to be able to write |> Program.runContentPage ...
https://github.com/fsprojects/Fabulous/blob/dda14abbf1d906de2fe576a4e7940bc94eb4df8c/Fabulous.XamarinForms/src/Fabulous.XamarinForms.Core/Program.fs#L53-L61

You would write your Fabulous app as usual, except for the App class

module ShareExt =
    type Model = ...
    type Msg = ...

    let init () = ...
    let update msg model = ...

    let view model dispatch =
        View.Grid(...) // Here, make sure you don't use a Page but a Control directly since the parent will be a ContentPage

type MyShareExtContentPage() as this =
    inherit Xamarin.Forms.ContentPage()

    let runner =
        XamarinFormsProgram.mkProgram init update view
        |> XamarinFormsProgram.runContentPage this

Then in your share extension, you can write

member this.ViewDidLoad() =
    global::Xamarin.Forms.Forms.Init()

    let xfPage = new MyShareExtContentPage()
    let newController = xfPage.CreateViewController()
    this.PresentModalViewController(newController, false)

from fabulous.xamarinforms.

bengobeil avatar bengobeil commented on May 27, 2024

Thanks for the incredibly detailed response. I will try it out and submit a PR if it works as well as described.

from fabulous.xamarinforms.

bengobeil avatar bengobeil commented on May 27, 2024

I suggest having some documentation for running any XF component as a Fabulous program. Seems like a very useful thing to know.

from fabulous.xamarinforms.

TimLariviere avatar TimLariviere commented on May 27, 2024

I suggest having some documentation for running any XF component as a Fabulous program. Seems like a very useful thing to know.

It's not an official feature yet. Only something I know is possible for simple use cases.
We still need to change a few things inside Fabulous to fully support this.
For instance, currently, only one Fabulous program loop can be active at any single time in the whole application, thus preventing having multiple XF components using Fabulous inside a single app.

But it's a planned feature. Once we add it, the documentation will be available as well. :)

from fabulous.xamarinforms.

bengobeil avatar bengobeil commented on May 27, 2024

OK I understand. Well, looks like it works, I haven't done any dynamic views yet but static ones work.

from fabulous.xamarinforms.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.